列出所有文件和目录而不使用联结递归

n61*_*007 5 windows ntfs recursive junction infinite-loop

在 Windows 中,是否有本机|便携式工具可以递归地为我提供一个路径下所有文件和目录的unicode系统本地兼容列表,而无需递归到连接点或链接中?

例如,内置dir takedown icacls命令与Application Data目录 ( 1 )一起运行到无限循环中。

编辑我希望能够获得一个文本文件或至少一个简单的剪贴板传输作为输出。

nix*_*xda 7

这在某种程度上是一个很难回答的问题。甚至 StackOverflow 也只有奇特的解决方案
但这里有一个简单的方法,用于在没有连接文件夹循环的情况下递归列出所有文件。

使用 PowerShell 并测试每个文件是否包含“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 
Run Code Online (Sandbox Code Playgroud)
  1. 将代码粘贴到文本文件中并将其保存为 PowerShell (.ps1) 脚本
  2. 将脚本放在您想要的文件夹中以递归列出所有文件+文件夹
  3. 使用 PowerShell 执行脚本。outputlist.txt将出现在同一位置调用的新文件

Powershell 脚本和常用批处理命令之间的快速比较

powershell  - good, no indefinite loops
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

batch "DIR /B /S" - bad, indefinite loops through junctions points
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明