返回列表 发帖

[原创代码] PowerShell获取jpg图片的exif信息并重命名

获取jpg图片的exif信息,根据拍摄日期对图片进行重命名。

1、查看模块路径
PS D:\Test> $Env:PsModulePath
D:\users\DAIC\My Documents\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules\

2、创建文件夹
md "D:\users\DAIC\My Documents\WindowsPowerShell\Modules\Image"

3、下载 Image 模块并解压缩到 D:\users\DAIC\My Documents\WindowsPowerShell\Modules\Image\
http://archive.msdn.microsoft.com/PSImage

4、执行代码

Import-Module Image
Get-ChildItem *.jpg | %{
    $picTaken = (Get-EXIF $_).DateTaken
    if ($picTaken) {
        $newName = (Get-Date $picTaken -uformat "%Y-%m-%d_%H-%M-%S") + ".jpg"
        $oldName = $_.BaseName + ".jpg"
        if ($oldName -ne $newName) {
            Rename-Item $oldName $newName
        }
    }
}COPY

返回列表