还是之前的老问题,各种来源的照片命名格式不统一,市面上的批量改名软件都比较卡顿。
这次让chatgpt来帮忙写代码:
![](https://i-blog.csdnimg.cn/blog_migrate/93659a1fd81e3a6fed46fbe8e6d12520.png)
on run {input, parameters}
set theFolder to choose folder with prompt "请选择一个文件夹"
tell application "Finder"
set theFiles to files of theFolder as alias list
repeat with i from 1 to the count of theFiles
set thisFile to item i of theFiles
set theInfo to the information of thisFile
try
set theDate to the creation date of thisFile
on error
set theDate to modification date of thisFile
end try
set theYear to year of theDate as string
set theMonth to text -2 thru -1 of (100 + (month of theDate as integer)) as string
set theDay to text -2 thru -1 of (100 + (day of theDate as integer)) as string
set theHour to text -2 thru -1 of (100 + (hours of theDate as integer)) as string
set theMinute to text -2 thru -1 of (100 + (minutes of theDate as integer)) as string
set theSecond to text -2 thru -1 of (100 + (seconds of theDate as integer)) as string
set theName to theYear & theMonth & theDay & "_" & theHour & theMinute & theSecond & "_" & i as string
set name of thisFile to theName & "." & name extension of thisFile
end repeat
end tell
return input
end run
再来一个windows版本。
![](https://i-blog.csdnimg.cn/blog_migrate/04db40373529ee203723ec38eb9e4fea.png)
@echo off
setlocal enabledelayedexpansion
set "srcfolder=%cd%"
set /p "srcfolder=请输入文件夹的完整路径:"
pushd %srcfolder%
set "counter=0"
for /f "tokens=*" %%i in ('dir /b /a-d') do (
set "filename=%%i"
for /f "tokens=1-6 delims=.: " %%j in ('dir /tc "!filename!"^|findstr /r /c:"[0-9][0-9]\.[0-9][0-9]\.[0-9][0-9]\ [0-9][0-9]"') do (
set "counter=!counter!+1"
set "newfilename=%%k_%%l_!counter!%%~xi"
echo Renaming "!filename!" to "!newfilename!"
ren "!filename!" "!newfilename!"
)
)
popd
最后,尝试一下用php实现。
![](https://i-blog.csdnimg.cn/blog_migrate/6ed275719e1bf7d034218348db51fe7a.png)
很完美。