【问题标题】:Powershell Copy-item errorPowershell 复制项错误
【发布时间】:2017-11-20 11:13:14
【问题描述】:

我想使用 powershell 复制目录中的文件列表:

$Dest="C:\temp"
$Fiches = ls -File '\\srv\share$\fiche*.pdf' #Fiches contains the list of all fiche*.pdf

foreach($Fiche in $Fiches){
   Copy-Item $Fiche $Dest #send me an error : "syntaxe incorrect" with this line underlined
}

有什么想法吗? (我的文件名包含空格)

【问题讨论】:

  • 粘贴确切的错误
  • Copy-Item : 文件名语法或目录不正确。 Au caractère \\SRV\share\myscript.ps1:6 : 5 + Copy-Item $Fiche $Dest + ~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified : (:) [Copy-Item], IOException + FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.CopyItemCommand
  • 我的分享包含$。这应该是问题所在。 \\srv\data$\
  • 使用-LiteralPath参数
  • 相同结果:Copy-Item -LiteralPath $Fiche $Dest

标签: powershell copy copy-item


【解决方案1】:

是 Dest 路径中的重音问题,抱歉这个不好的问题

【讨论】:

    【解决方案2】:

    使用Copy-Item获取完整路径时,指定.FullName$Fiche的属性:

    $Dest="C:\temp"
    $Fiches = Get-ChildItem -File '\\srv\share$\fiche*.pdf' #Fiches contains the list of all fiche*.pdf
    
    foreach($Fiche in $Fiches){
       Copy-Item $Fiche.FullName -Destination $Dest
    }
    

    【讨论】:

    • 我的文件名包含空格
    猜你喜欢
    • 2012-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-16
    • 1970-01-01
    相关资源
    最近更新 更多