我正在尝试将所有文​​件从源目录复制到目标目录,如果不存在,则应使用Copy-Item创建该目录。

第一次尝试:
复制项'C:\ sourcePath \ reports''C:\ destPath \ reports'-Force -Recurse

一切都很好。但是,如果我再次运行该命令,则Powershell而不是复制C:\ sourcePath \ reports中的内容,而是在C:\ destPath \ reports下创建一个附加的报告子文件夹。我最终得到了C:\ destPath \ reports \ reports。

其他尝试:

复制项目'C:\ sourcePath \ reports *''C:\ destPath \ reports'-强制-递归
这不会创建目标路径C:\ destPath \ reports

复制项目'C:\ sourcePath \ reports **''C:\ destPath \ reports'-强制-递归
这将内容复制到报告文件中,而不是文件夹中。

有谁知道如何使它工作?这个

最佳答案

使用robocopy。它是为此类任务而设计的。

robocopy C:\sourcePath\reports C:\destPath\reports /s

10-05 21:04
查看更多