如何告诉'PowerShell'复制项目无条件复制文件


82

如果资源不存在,以下PowerShell脚本将起作用。

  Copy-Item $src_dir $dst_dir$agent_folder -recurse

但是如果有资源,它将说:

+   Copy-Item <<<<  $src_dir $dst_dir$agent_folder -recurse
    + CategoryInfo          : ResourceExists: (C:\Users\Pac\Desktop\Agents\Agent0\lib:S
   tring) [Copy-Item], IOException
    + FullyQualifiedErrorId : DirectoryExist,Microsoft.PowerShell.Commands.CopyItemComm
   and

我必须在命令中添加些什么,以便它无条件地复制文件?

Answers:



19

从文档(help copy-item -full):

-force <SwitchParameter>
    Allows cmdlet to override restrictions such as renaming existing files as long as security is not compromised.

    Required?                    false
    Position?                    named
    Default value                False
    Accept pipeline input?       false
    Accept wildcard characters?  false

4
我猜为false表示参数不是强制性的,而False表示默认值为$ false
fredericrous
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.