此脚本的工作方式与前一个问题相同,可将@ 2x添加到文件夹中的所有文件中,但如何创建或更改此Apple脚本以删除@ 2x。
set appendable to "@2x"
set theFolder to choose folder
tell application "Finder"
set theFiles to (files of entire contents of theFolder) as alias list
repeat with theFile in theFiles
set FileExtension to theFile's name extension as string
set FileName to theFile's name as string
set FileBaseName to text 1 thru ((offset of "." in FileName) - 1) of FileName
set theFile's name to FileBaseName & appendable & "." & FileExtension
end repeat
end tell
答案 0 :(得分:2)
tell application "Finder"
repeat with f in (files of entire contents of (choose folder) as alias list)
set n to name of f
set x to name extension of f
if n does not end with "@2x." & x then next
set name of f to text 1 thru (-5 - (count x)) of n & "." & x
end repeat
end tell
在shell中执行此操作会更容易:IFS=$'\n'; for f in $(find ~/Desktop -name '*@2x*'); do mv "$f" "${f//@2x/}"; done
。