首页 > 解决方案 > 使用 Powershell 递归复制文件和文件夹

问题描述

在 vbscript 中,我有一些代码可以使用 powershell 命令递归地复制文件和文件夹:

pCommand = "Copy-Item " & sourcePath & " " & destinationPath & " -Recurse -Force"
oShell.Run("powershell.exe -Command "" & " & pCommand & """"), 1, True

直到几个月前,这一直可以正常工作,但现在,我不确定原因,它不会复制所有文件,也不会保留所有结构。

例如,结构如下:

sourcePath\Report\Act1\Row0

sourcePath\Report\Act2\Row0

sourcePath\Report\Act3\Row0

...

sourcePath\Report\icons

sourcePath\Report\Resources\Checkpoints

在目标路径上,我最终得到:

destinationPath\Report\Act1\Row0

destinationPath\Report\Act2   (subfolder Row0 is not created)

destinationPath\Report\Act3   (subfolder Row0 is not created)

...

destinationPath\Report\icons => folder created but files within the folder are not copied

在执行期间,我不断看到这些类型的消息:

Copy-Item:目标文件“...\Report\Act3”是一个目录,而不是一个文件。

Powershell 有什么变化吗?我可以改用 objFSO.CopyFolder。它工作正常,但速度要慢得多。

谢谢

标签: powershellfile-copying

解决方案


推荐阅读