【问题标题】:Use Powershell to duplicate a directory's child names on a copy of a single JPG使用 Powershell 在单个 JPG 的副本上复制目录的子名称
【发布时间】:2014-10-27 07:54:06
【问题描述】:

我有一个包含 24 个唯一图像文件的目录。每个图像文件都有一个唯一且有意义的名称。我们在数据库中引用文件名,并将它们呈现在网站上。我想用 JPG 占位符图像替换每个独特的图像。我的想法是创建那个 JPG 占位符图像,创建 24 个副本,然后给每个副本一个来自原始目录的唯一且有意义的名称。

创建占位符图像后,我需要以下 PowerShell 命令:

Get the placeholder image.
For each legacy image in the legacy folder:
- Get its base name.
- Create a copy of the placeholder image.
- Name the placeholder copy with the legacy base name.
Done.

无论如何,这并不重要 - 我认为使用 PowerShell 来做这件事会很棒。

【问题讨论】:

    标签: file powershell copy powershell-3.0 directory


    【解决方案1】:

    宾果游戏!

    Get-ChildItem '.\Legacy Items' -filter *.jpg | ForEach-Object `
    { `
        Copy-Item .\735x379.jpg .\Placeholders\$_ `
    }
    

    请注意,重音符 ` 字符可以让我们在 PowerShell 中执行多行命令。

    【讨论】:

      猜你喜欢
      • 2019-07-12
      • 2013-03-19
      • 1970-01-01
      • 2021-08-08
      • 2013-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多