我正在尝试重命名某些文件,然后将它们复制到备份位置,如下所示:

gci $src `
    | ?{!$_.psiscontainer -and $_.extension.length -eq 0 -and $_ -match "tmp_\d{1}$"} `
    | %{ ren -path $_.fullname -new ($_.name + ".ext") } `
    | %{ cpi -path $_.fullname -dest $bkup -force}

重命名部分工作正常。但是,重命名的文件不会复制到备份位置。我在这里做错了什么?

最佳答案

默认情况下,重命名的项目不会被推回管道,请使用-PassThru开关将其传递:

gci $src `
    | ?{!$_.psiscontainer -and $_.extension.length -eq 0 -and $_ -match "tmp_\d{1}$"} `
    | %{ ren -path $_.fullname -new ($_.name + ".ext") -PassThru } `
    | %{ cpi -path $_.fullname -dest $bkup -force}

关于powershell - 重命名,然后复制不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6479488/

10-16 10:38