用 Copy-Item -Recurse 复制整个文件夹

PowerShell 自带的递归复制命令,很多人忘了它的存在,总去用 xcopy 或 robocopy。

Windows文件复制PowerShell低风险
使用 Copy-Item -Path <源> -Destination <目标> -Recurse 即可复制文件夹及其全部内容。

01命令

命令
$ Copy-Item -Path 'C:\Source\Project' -Destination 'D:\Backup\Project' -Recurse

02作用说明

不加 -Recurse 时 Copy-Item 只复制顶层文件,常让人以为它不能递归。目标文件夹不存在时会自动创建;加 -Force 才会覆盖只读或已存在的文件。用通配符 C:\Source\* -Destination D:\Backup -Recurse 则是复制“内容”而不是生成嵌套的子文件夹。

03风险

风险低风险
使用条件PowerShell
!注意: 目标目录已有同名文件时,加 -Force 会直接覆盖且不提示确认。

04撤销

撤销
$ Remove-Item -Path 'D:\Backup\Project' -Recurse -Force

05来源

  • Copy-Item - PowerShell
    SS64 · technical · 2026-09-17
    依据: SS64 lists -Recurse for recursive copy and -Force to overwrite existing destination files.
  • Copy-Item | Microsoft Learn
    Microsoft · vendor-doc · 2026-09-17
    依据: Microsoft documents that Copy-Item -Recurse copies the contents of a folder including its subdirectories, and that -Force overwrites read-only items.

最后验证: 2026-09-17 · 分类: 文件与文件夹

06相关方案