复制项目我在做什么错?

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

jamssen 回答:复制项目我在做什么错?

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

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

`

本文链接:https://www.f2er.com/3141411.html

大家都在问