【问题标题】:Copying 8 files from a folder to 40 other subfolders将 8 个文件从一个文件夹复制到 40 个其他子文件夹
【发布时间】:2013-07-10 13:51:31
【问题描述】:

我尝试制作一个脚本,将所有(8 个文件)文件从一个文件夹复制到大约 40 个文件夹的特定子文件夹中......

我以 * 开头,将所有文件从该文件夹中复制出来。 但当然不是这样:

带有 * 的文件夹名称随机更改,并且有一个名为 EmailTemplates 的子文件夹应该可以获取我所有的 8 个文件。

Copy-Item d:\www\example\*   -destination d:\example\2\*\EmailTemplates

有简单的解决方案吗? 提前致谢!

【问题讨论】:

    标签: powershell copy powershell-2.0


    【解决方案1】:

    这样的东西可以用来选择目标文件夹吗?

    $destination = Get-ChildItem "D:\example\2" -Recurse | ? {
        $_.PSIsContainer -and $_.Name -eq "EmailTemplates"
      }
    

    否则您可能必须像这样确定目的地:

    $destination = Get-ChildItem "D:\example\2" |
      ? { $_.PSIsContainer } |
      % { Join-Path $_.FullName "EmailTemplates" } |
      ? { Test-Path -LiteralPath $_ } | Get-Item
    

    然后像这样复制文件:

    Get-ChildItem "d:\www\example" | ? { -not $_.PSIsContainer } | % {
      Copy-Item $_.FullName $destination.FullName
    }
    

    【讨论】:

    • 谢谢,帮了我很多,我做了一些不同的事情,但你帮我做到了
    猜你喜欢
    • 1970-01-01
    • 2021-05-17
    • 1970-01-01
    • 1970-01-01
    • 2022-08-04
    • 2015-05-23
    • 2011-08-22
    • 2012-07-28
    • 2023-01-14
    相关资源
    最近更新 更多