【发布时间】:2013-06-09 04:22:12
【问题描述】:
我正在尝试将所有文件从源目录复制到目标目录,如果该目录不存在,则应使用 Copy-Item 创建。
第一次尝试: 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' -Force -Recurse 这个不会创建目标路径 C:\destPath\reports
复制项目 'C:\sourcePath\reports**' 'C:\destPath\reports' -Force -Recurse 这会将内容复制到报告文件中,而不是文件夹中。
有人知道如何让它工作吗?这个
【问题讨论】:
-
copy-item 处理目录副本的方式似乎存在错误,请参阅this link。您可以做一些更复杂的事情并事先检查文件夹的存在。否则,我不想这么说,但 robocopy 可能是要走的路。
标签: powershell