Topic starter 18/06/2021 12:48 pm
I've been trying to find a script that recursively prints all files and folders within a directory like this where the backslash is used to indicate directories:
Source code\ Source code\Base\ Source code\Base\main.c Source code\Base\print.c Sample.txt
I'm using PowerShell 3.0 and most other scripts I've found do not work (though they didn't anything like what I'm asking).
Additionally: I need it to be recursive.
myTechMint liked
18/06/2021 5:55 pm
What you are likely looking for is something to help distinguish a file from a folder. Luckily there is a property call PSIsContainer that is true for folder and false for files.
dir -r | % { if ($_.PsIsContainer) { $_.FullName + "\" } else { $_.FullName } }
C:\Source code\Base\ C:\Source code\List.txt C:\Source code\Base\main.c C:\Source code\Base\print.c
If the leading path information is not desirable, you can remove it easily enough using -replace:
dir | % { $_.FullName -replace "C:\\","" }
Hopefully this gets you headed off in the right direction.
Neha liked