Powershell: Move Files recursively

◇◆丶佛笑我妖孽 提交于 2019-12-04 05:22:31

You could replace the Move-Item command with an Copy-Item command and after that, you can delete the files you moved by simply calling Remove-Item:

$a = ls | ? {$_.Name -notlike "ProjectXXX.*" -and $_.Name -ne "config.log4net" -and $_.Name -ne $binFolderName }
$a | cp -Recurse -Destination bin -Force
rm $a -r -force -Confirm:$false

As already stated, Move-Item will not overwrite folders so you're left with copying. An alternative solution would be to call Robocopy for each file in your for-each loop with the /MOV switch (amongst others!); this will move then delete the source file.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!