我尝试使用-force,但仍然收到错误消息
Copy-Item :具有指定名称C:\folder2的项目已存在。
Copy-Item 'c:\folder1' -Destination 'c:\folder2' -force发布于 2021-11-29 16:17:57
您可以先创建目标文件夹,然后通过将\*添加到路径来复制源文件夹中的所有内容:
# first create the destination folder if it does not already exist
$null = New-Item -Path 'c:\folder2' -ItemType Directory -Force
# then copy all from the source folder to the destination
Copy-Item -Path 'c:\folder1\*' -Destination 'c:\folder2' -Recurse -Force通过在New-Item命令上使用switch -Force,cmdlet将返回新创建的文件夹的对象或现有文件夹的对象。
在这两种情况下,我们都不需要该输出,因此我们将使用$null =忽略它
https://stackoverflow.com/questions/70147688
复制相似问题