Looking to build a tree of directories and files, with output quite similar to that of the tree
command. With the additional functionality that the actual files can be piped to powershell in order to, for example, here, search with regex
through the files.
The Calibre
library holds a number of files.
Attempting to loop through its directories and sub-directories:
$files = Get-ChildItem "/home/nicholas/Calibre Library/"
foreach ($f in $files){
$outfile = $f.FullName + "out"
Get-Content $f.FullName | Where-Object { ($_ -match 'step4' -or $_ -match 'step9') } | Set-Content $outfile
}
But, that just generates pages of errors:
11 | Get-Content $f.FullName | Where-Object { ($_ -match 'step4' -or $ …
| ~~~~~~~~~~~~~~~~~~~~~~~
| Unable to get content because it is a directory: '/home/nicholas/Calibre Library/Unknown'. Please use
| 'Get-ChildItem' instead.
The notion is to search ".txt" files using regex
. First, need to loop through the ".txt" files in the Calibre
library.
(Or, perhaps, just pass the output of "tree" to powershell? Might be far more pragmatic? The 'tree' command certainly works from the REPL console. At least on Linux. I'll perhaps make that a seperate question.)