我想知道使用Robocopy解决方案是否比使用Get-ChildItem
获取给定文件夹(包括子文件夹)中的文件列表更快。
在我的代码中,我使用Get-ChildItem
命令获取特定文件夹中所有文件的列表,以便循环处理每个文件:
$files = Get-ChildItem "C:\aaa" -Recurse | where {! $_.PIsContainer} # ! because I don't want to list folders
foreach ($file in $files){
...
}
现在,我有robocopy命令来获取所有文件的列表,但是robocopy的输出结果是一个字符串。
[string]$result = robocopy "C:\aaa" NULL /l /s /ndl /xx /nc /ns /njh /njs /fp
那么,我该如何使用robocopy命令的输出来循环处理每个文件(类似于使用
Get-ChildItem
的方式)呢?请保留HTML标记。
where {! $_.PSIsContainer}
并只执行$files = Get-ChildItem "C:\aaa" -Recurse -File
来仅检索文件,这可能会提高性能。 - Lance U. Matthews