我想将文件从一个位置移动到另一个位置,但不想从我移动文件的目录中的子文件夹中移动任何文件。
我有以下代码,但这会移动子文件夹中的文件。此外,扩展名应仅为 .xml 和 .pdf。
此脚本将所有文件从$MoveThese
目标移动到目标,即使是子文件夹中的文件,例如C:\Test\Folder1\Subfolder
. 任何的意见都将会有帮助。
$MoveThese = "C:\Test\Folder1", "C:\Test2\Folder2", "C:\Test3\Folder3"
$Destination = "C:\Test\Docs", "C:\Test2\Docs", "C:\Test3\Docs"
For($i=0; $i -lt $FailFolders.Length; $i++){
Get-ChildItem -Path $MoveThese[$i] -Recurse -Include "*.xml", "*.pdf" | Move-Item -Destination $Destination[$i]
}
如果您不想要子文件夹中的文件,请不要使用-Recurse
. 按照GET-ChildItem文档本“中的指定位置获取的项目,并在所有子项的位置。”
遗漏了这部分-Include
声明:
-Include 参数只有在命令包含 -Recurse 参数时才有效
解决方案:
Get-ChildItem $MoveThese[$i] -File |
Where-Object {$_.Extension -in @(".xml",".pdf")} |
Move-Item -Destination $Destination[$i]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句