【问题标题】:Replacing an images with different file names with one image用一个图像替换具有不同文件名的图像
【发布时间】:2020-04-14 22:30:34
【问题描述】:

我正在做一个项目,需要替换很多图片:

我有一个图像 1.png 需要替换大约 40 个不同名称的不同 png 文件,例如 2.png、3.png 等。重要的是当 1.png 替换 2.png、3.png 等时. 文件名不变。也就是说,1.png 的内容应该替换 2.png 和 3.png 的内容,但不应该替换文件名。

我不确定这是否可行,但是如果可以的话,我会很高兴听到如何。

【问题讨论】:

  • 您最终要达到什么目标?为什么要以 40 个不同的名称将 40 个相同图像的副本存储 40 次?

标签: file


【解决方案1】:

我认为您可以使用 powershell 来实现这一点。

类似的东西。

$files = Get-ChildItem -Path 'c:\source\folder' -Recurse
ForEach ($file In $files)
{
    Write-Host 'Replacing:'$file.FullName
    If ($file.Name -eq '2.png')
    {
        Copy-Item -Path 'c:\source\file\1.png' -Destination $file.FullName -Force
        Rename-Item -Path $file.FullName -NewName "2.png"
    }
}

这里是一个链接,以防您之前没有创建过 PS 脚本

https://www.windowscentral.com/how-create-and-run-your-first-powershell-script-file-windows-10

【讨论】:

    猜你喜欢
    • 2021-12-26
    • 1970-01-01
    • 2022-10-14
    • 2016-07-04
    • 2018-12-12
    • 1970-01-01
    • 2012-12-17
    • 2015-02-17
    • 1970-01-01
    相关资源
    最近更新 更多