【问题标题】:powershell update file in subfolders if it already exists子文件夹中的powershell更新文件(如果已存在)
【发布时间】:2013-07-15 11:16:50
【问题描述】:

我不敢相信这会像我发现它一样困难。

我在服务器共享上有一个文件夹。此文件夹有许多子文件夹,其中可能包含或不包含我想用最新版本覆盖的文件。

我做了很多谷歌搜索,发现下面的命令可以得到我想要的:

Get-ChildItem \\server1\websites\website\xml -Name "description-15240.txt" -Recurse | Copy-Item ".\description-15240.txt" -Destination $_.fullname

...但事实并非如此。

因此,我将命令分解为多个部分并发现 Get-ChildItem 仅返回来自 -Name 参数根目录的文件路径,即

1\infinite\description-15240.txt 68\无限\description-15240.txt 79\无限\description-15240.txt 80\无限\description-15240.txt

而不是我所追求的 \server1\websites\website\xml\1\infinite\description-15240.txt。

问题:我无法让 Get-ChildItem 返回完整路径 | { $_.FullName } 不这样做 | { $_.Parent }也没有

有人可以帮助并可能告诉我Copy-Item 是否也可以工作吗?

非常感谢,N

【问题讨论】:

    标签: powershell get-childitem copy-item


    【解决方案1】:

    Name参数只过滤文件名,如果你想要文件的完整路径使用include参数。

    Get-ChildItem \\server1\websites\website\xml -include "description-15240.txt" -Recurse | % { Copy-Item ".\description-15240.txt" -Destination $_.fullname }
    

    【讨论】:

      【解决方案2】:

      试试

      gci \\server1\websites\website\xml -Name "description-15240.txt" -recurse |%{ convert-path $_.pspath}
      

      【讨论】:

      • 这是正确的吗?我在尝试时收到 Convert-Path : Cannot bind argument to parameter 'Path' because it is null 错误。
      猜你喜欢
      • 2014-09-07
      • 2018-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-30
      • 2011-02-19
      • 1970-01-01
      相关资源
      最近更新 更多