【发布时间】:2022-10-22 09:29:35
【问题描述】:
我必须调整很多文件以删除它们的最后一部分:
由此:108595-1121_gemd_u65_stpetenowopen_em_f_2021-12-03T161809.511773.zip
对此:108595-1121_gemd_u65_stpetenowopen_em_f.zip
总是需要删除 24 个字符,并且开头总是有一个下划线。其余的是随机数和字符。我在下面找到了删除数字的代码,但我需要字符。
我的目标是将其与其他一些进程一起放入自动机脚本中,但 Automator 中的重命名器不够健壮。
我怎样才能让它去掉 X 个字符?
on run {input, parameters}
repeat with thisFile in input
tell application "Finder"
set {theName, theExtension} to {name, name extension} of thisFile
if theExtension is in {missing value, ""} then
set theExtension to ""
else
set theExtension to "." & theExtension
end if
set theName to text 1 thru -((count theExtension) + 1) of theName -- the name part
set theName to (do shell script "echo " & quoted form of theName & " | sed 's/[0-9]*$//'") -- strip trailing numbers
set name of thisFile to theName & theExtension
end tell
end repeat
return input
end run
【问题讨论】:
标签: shell applescript