3 ms·
dir works because it's actually an alias of Get-ChildItem, which returns a list of objects (DirectoryInfo or FileInfo). My example was specifically a list of pa
by Jenk 5y ago
dir works because it's actually an alias of Get-ChildItem, which returns a list of objects (DirectoryInfo or FileInfo). My example was specifically a list of paths that are not objects but just strings.
- tyingq 5y agoOkay. How about "echo"? (Aliased to Write-Output, which I assume is strings) C:\temp> dir file3 Directory: C:\temp Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 9/10/2021 1:03 PM 0 file3 C:\temp> echo "file3" | Remove-Item C:\temp> dir file3 dir : Cannot find path 'C:\temp\file3' because it does not exist. Edit: I see it now. It works with one string, but if I Write-Output "file1`r`nfile2" | Remove-Item it no longer works because it takes the whole string as an object. I'd have to pipe an array of strings rather than cr-lf separated strings. This does work: C:\temp> $foo="file1`r`nfile2" C:\temp> $foo -split '\r?\n' | Remove-Item
- Jenk 5y agoYeah, another one I haven't worked out yet is opening mulitple files from shell. So far this is what I can come up with: @(Get-ChildItem *.ts | foreach { $_.Name } | Join-String -Separator ' ') | foreach { nvim -- $_ } But even that abomnination doesn't quite work.
- deleted 5y ago[deleted]
- jiggawatts 5y agoI suspect that this is sufficient for your needs: nvim -- (( dir *.ts ).Name -join ' ') I don't have nvim, but the equivalent worked for me with "code" (VS Code).
- Jenk 5y agoThat does indeed work but it's quite different from piping. But thanks that has increased my productivity! I use fzf a lot so I'll be adapting it for that too :)