如何使用 Powershell 跨卷移动文件/文件夹? [英] How do you move files/folders across volumes with Powershell?
问题描述
我尝试使用 PowerShell 移动文件夹
I try to move a folder with PowerShell
move-item c:\test c:\test2
有效,但是
move-item c:\test \\192.168.1.50\c$\test2
没有告诉我
移动项目:来源和目的地路径必须具有相同的根.移动不能跨卷工作.
Move-Item : Source and destination path must have identical roots. Move will not work across volumes.
推荐答案
如果 test
是一个目录,它将不起作用,因为 Move-Item
的文档说明:
If test
is a directory, it won't work, as the documentation for Move-Item
states:
Move-Item
将在同一提供程序支持的驱动器之间移动文件,但它只会在同一驱动器内移动目录.
Move-Item
will move files between drives that are supported by the same provider, but it will move directories only within the same drive.
在这种情况下,您可以使用 Copy-Item
后跟 Remove-Item
:
You can use Copy-Item
followed by a Remove-Item
in that case:
try {
Copy-Item -Recurse C:\test \\192.168.1.50\c$\test2 -ErrorAction Stop
Remove-Item -Recurse c:\test
} catch {}
如果您不依赖 PSDrives,另一种选择是简单地使用 xcopy 或 robocopy.
Another option, if you don't rely on PSDrives, would be to simply use xcopy or robocopy.
这篇关于如何使用 Powershell 跨卷移动文件/文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!