powershell PowerShell文件,用于根据图像尺寸递归重命名和编辑目录中的图像。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell PowerShell文件,用于根据图像尺寸递归重命名和编辑目录中的图像。相关的知识,希望对你有一定的参考价值。


# This gets the correct path to the directory of execution
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition

# Create variable from passed argument in command line
$filePath = $args[0]

# Get FullPath of file
$fullpath = [System.IO.Path]::GetFullPath(($filePath))

Get-ChildItem -Recurse $fullpath |
ForEach-Object {

    # File is not this filename
    if ($_.BaseName -eq "filesize") {
        return
    }

    # File is a folder (shouldn't be any folder inside JPEG)
    if($_.GetType().FullName -eq "System.IO.DirectoryInfo") {
        return #I want to delete this entire folder
    }

    # File is an image
    if( $_.Extension -eq ".jpg") {

        # Get image object
        $img = [System.Drawing.Image]::FromFile($_.FullName)

        # Check Size and do something
        if($img.PhysicalDimension.Width -eq 1024) {
            $img.Dispose()
            Rename-Item $_.FullName "$($_.Directory.Parent.BaseName)-kelly-tooke-leather_$(Get-Random).jpg".Replace(" ","-")
        } elseif($img.PhysicalDimension.Width -eq 637) {
            $img.Dispose()
            Remove-Item $_.FullName
        }
        return
    }
    

}

以上是关于powershell PowerShell文件,用于根据图像尺寸递归重命名和编辑目录中的图像。的主要内容,如果未能解决你的问题,请参考以下文章

powershell自启内存占用

Powershell - 新用户主文件夹权限

powershell 一个ps1 运行

Win10怎么安装windows powershell……

用PowerShell代替批处理吧!

Powershell 比较 CSV文件