复制项目我在做什么错?

时间:2019-11-07 21:55:07

标签: powershell

Copy-Item每次使我绊倒。有人可以告诉我我在这里做错了吗?

我有一组文件夹:

C:\FolderA\Thing\Sub1\1_file.css
C:\FolderA\Thing\Sub2\A_file.css
C:\FolderA\Thing\page.html

我尝试使用Copy-Item将它们发送到C:\FolderB\*并保留结构:

Copy-Item -Path $srcFolder\Thing\* -Destination $destFolder\Thing -Recurse -Force -Verbose

预期结果:

C:\FolderB\Thing\Sub1\1_file.css
C:\FolderB\Thing\Sub2\A_file.css
C:\FolderB\Thing\page.html

相反,我最终得到:

C:\FolderB\Sub1\1_file.css
C:\FolderB\Sub2\A_file.css
C:\FolderB\page.html

这里显然有一个\Thing文件夹,所以如果我告诉它递归进行,为什么它不创建\Thing

1 个答案:

答案 0 :(得分:0)

您需要告诉它在复制之前创建目录,例如:

$dst = C:\FolderB\Thing
New-item $dst -type directory

`

相关问题