我想使用 Powershell 扫描并将文件夹(包括子文件夹甚至更深层次的文件夹)从一个文件夹移动到另一个文件夹。
目前,我正在使用以下命令管道。
Get-ChildItem -recurse -path sub\WORK -filter "* OK" | Where-Object { $_.PSIsContainer } | foreach { Move-Item -path $_ -destination sub\OK }
很不幸,它不能正常工作,因为找到的结果是相对于.\sub\WORK
的,当尝试移动它们时,Move-Item会抱怨这些文件夹不在当前文件夹中:
Move-Item : Cannot find path 'C:\TMP\2011-12-12 test 2 OK' because it does not exist.
我希望$_包含:'C:\TMP\sub\WORK\2011-12-12 test 2 OK'
,因为这些是PowerShell中的对象,而不是像Linux中的字符串。