Is there a native|portable tool that can give me a unicode or a system local-compatible list of all files and directories under a path recursively, without recursing into junction points or links, in Windows?
For example, the built-in dir
takedown
icacls
commands run into an infinite loop with the Application Data directory (1).
EDIT I would like to be able to get a text file or at least an easy clipboard transfer as an output.
Answer
This was somehow a hard question. Even StackOverflow has only fancy solutions.
But here is a simple one for listing all files recursively without junction folder loops.
Use PowerShell and test each file if it contains the attribute "ReparsePoint"
function Recurse($path) {
$fc = new-object -com scripting.filesystemobject
$folder = $fc.getfolder($path)
foreach ($i in $folder.files) { $i | select Path }
foreach ($i in $folder.subfolders) {
$i | select Path
if ( (get-item $i.path).Attributes.ToString().Contains("ReparsePoint") -eq $false) {
Recurse($i.path)
}
}
}
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
$outputlist = Recurse($scriptPath) | Out-File -Filepath .\outputlist.txt
- Paste the code into a text file and save it as PowerShell (.ps1) script
- Place the script inside your desired folder to list all files+folder recursively
- Execute the script with PowerShell. A new file called
outputlist.txt
at the same location will appear
Quick comparison between the Powershell script and a common batch command
powershell - good, no indefinite loops
batch "DIR /B /S" - bad, indefinite loops through junctions points
Comments
Post a Comment