我想使用Powershell扫描并移动文件夹(和子文件夹或更深层)从一个文件夹到另一个文件夹。Get-ChildItem结果看起来像Powershell中的相对路径
目前我正在使用这个命令管道。
Get-ChildItem -recurse -path sub\WORK -filter "* OK" | Where-Object { $_.PSIsContainer } | foreach { Move-Item -path $_ -destination sub\OK }
遗憾的是它不工作,因为找到的结果是相对于.\sub\WORK
,试图转移它们的布展项目抱怨说,文件夹是不是在当前文件夹时:
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中的字符串。
这对我来说看起来像一个bug,但我的powershell经验有点太低,不提这样的事情。如果我在'Get-ChildItem'中添加'-include'* OK'',那么它也可以工作。你的解释非常有帮助。 –
好吧,你不应该依赖于ToString(),除非你拥有所有的东西。 :) – JasonMArcher