【问题标题】:Copy-item Files and Folders in Folder of Jenkins server using PowerShell使用 PowerShell 复制 Jenkins 服务器文件夹中的项目文件和文件夹
【发布时间】:2021-05-29 00:22:19
【问题描述】:

我想复制/粘贴其他路径中的所有文件和所有文件夹。

5月数据为:

temp
  Deploiement    
    foo.xml
    bar.xml
    Documentation
    brute

我阅读了https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/copy-item?view=powershell-7.1 上的官方文档并找到了这个例子:

Example 3: Copy directory and contents to a new directory
Copy-Item -Path "C:\Logfiles\*" -Destination "C:\Drawings\Logs" -Recurse

在我的 Jenkins 中,我这样写:

Copy-Item -Path "temp/Deploiement/*" -Destination "Deploy" -Recurse

控制台错误:

Copy-Item : Container cannot be copied onto existing leaf item.
At D:\JenkinsWks\workspace\pic\temp\Scripts\packer.ps1:114 char:2
+     Copy-Item -Path "temp/Deploiement/*" -Destination "Deploy" - ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (D:\JenkinsWks\w...t\Documentation:String) [Copy-Item], PSArgumentException
    + FullyQualifiedErrorId : CopyContainerItemToLeafError,Microsoft.PowerShell.Commands.CopyItemCommand
 
Copy-Item : Container cannot be copied onto existing leaf item.
At D:\JenkinsWks\workspace\pic\temp\Scripts\packer.ps1:114 char:2
+     Copy-Item -Path "temp/Deploiement/*" -Destination "Deploy" - ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (D:\JenkinsWks\w...nt\brute:String) [Copy-Item], PSArgumentException
    + FullyQualifiedErrorId : CopyContainerItemToLeafError,Microsoft.PowerShell.Commands.CopyItemCommand

【问题讨论】:

    标签: powershell


    【解决方案1】:
    if (-Not (Test-Path "Deploy")) {
        md -path "Deploy"
    }
    Copy-Item -Path "temp/Deploiement/*" -Destination "Deploy" -Recurse
    

    【讨论】:

      猜你喜欢
      • 2013-07-24
      • 1970-01-01
      • 1970-01-01
      • 2015-09-20
      • 1970-01-01
      • 2011-09-26
      • 1970-01-01
      • 2019-10-19
      • 1970-01-01
      相关资源
      最近更新 更多