我使用 MacOSX Lion,但我对 Windows 的解决方案也很满意,因为我在虚拟机中有 Windows XP:
我有数百个文件名中带有unix时间戳的文件,如下所示:
1341131403_-_db123456.sql.gz
1341390599_-_db123456.sql.gz
1341563401_-_db123456.sql.gz
我希望将时间戳转换为可读时间戳,并使用该可读时间戳重命名文件,如下所示:
2012-07-01 08-30-03.sql.gz
2012-07-04 08-29-59.sql.gz
2012-07-06 08-30-01.sql.gz
我花了几个小时在一个 applescript 解决方案上,但没有成功:
on open (the_input)
tell application "Finder"
set the_files to every item of the_input
set the_count to count of the_files
repeat with i from 1 to the_count
set current_file to item i of the_files
set old_name to (name of current_file) as string
set old_name to trim_line(old_name, "_-_db123456. sql. gz", 1)
set new_name to (result of uts_convert(old_name)) as string
set the name of current_file to (new_name & file type of current_file)
end repeat
end tell
end open
on uts_convert(input)
set shellcommand1 to "date -r "
set shellcommand2 to " \"+%Y-%m-%d %H-%M\""
set the_output to do shell script (shellcommand1 & input & shellcommand2)
return the_output
end uts_convert
任何帮助表示赞赏!我不在乎它是用 applescript 还是简单的终端命令或其他什么来完成的。
提前致谢!