【问题标题】:powershell Get-Item how to denote destination is a folder to be created?powershell Get-Item 如何表示目标是要创建的文件夹?
【发布时间】: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 这会将内容复制到报告文件中,而不是文件夹中。

有人知道如何让它工作吗?这个

【问题讨论】:

标签: powershell


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2017-12-11
    • 1970-01-01
    • 1970-01-01
    • 2020-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-02
    • 1970-01-01
    相关资源
    最近更新 更多