本帖最后由 yep96 于 2022-4-4 17:29 编辑
备份照片时,无论是从手机复制出来还是从云盘上下载到本地,照片的创建、修改时间都会变成导出当天,软件识别错误强迫症也很不爽。
这个脚本利用Powershell可以简单的通过文件名修改创建时间,并统一文件名形式
支持 开头年月日-时分秒结尾, 开头年月日_时分秒结尾, 开头_年-月-日-时-分-秒_结尾等多种格式,并统一成
开头_年月日_时分秒_结尾。
有些图片没有EXIF信息或EXIF信息也是错误的,本脚本也可以修改,下载jhead(https://www.sentex.ca/~mwandel/jhead/)并放在同一目录即可,但这样会修改原文件且不可逆。
[PowerShell] 纯文本查看 复制代码
# $path = $pwd.Path+'\Screenshots\'
$path = $pwd.Path+'\Camera\'
$EXIF = 0
if ($EXIF -and $(Read-Host "确认修改EXIF请输入EXIF") -ceq "EXIF")
{
$EXIF = 1
}
foreach ($file in ls $path)
{
$NAME = $file.Name
if ($file.Name -match "^([^\d]*?)[_-]?(\d{8})-?(\d{6}.*)$")
{
$file.MoveTo($path+$matches[1]+'_'+$matches[2]+'_'+$matches[3])
}
elseif ($file.Name -match "^([^\d]*?)[_-]?(\d{4})-(\d{2})-(\d{2})-(\d{2})-(\d{2})-(\d{2}.*)$")
{
$M = $matches
$file.MoveTo($path+$M[1]+'_'+$M[2]+$M[3]+$M[4]+'_'+$M[5]+$M[6]+$M[7])
}
if ($file.Name -match "^[^\d]*(\d{4})(\d{2})(\d{2})_(\d{2})(\d{2})(\d{2}).*$")
{
$M = $matches
$date = $($M[1]+'/'+$M[2]+'/'+$M[3]+' '+$M[4]+':'+$M[5]+':'+$M[6])
if ($EXIF)
{
$time = $M[1]+':'+$M[2]+':'+$M[3]+'-'+$M[4]+':'+$M[5]+':'+$M[6]
jhead -mkexif $path$file
jhead "-ts$time" $path$file
}
$file.creationtime = $date
$file.lastwritetime = $date
$file.lastaccesstime = $date
$NAME+'成功修改 ->'+$file.Name
} else
{
$NAME+'修改失败!!!!!!!!'
}
}
pause
|