如何在AppleScript中获取不带扩展名的文件名?例如:
Penny.Dreadful.S03E01.720p.HDTV.x264-BATV.mp4
到
Penny.Dreadful.S03E01.720p.HDTV.x264-BATV
一个文件足以满足我的需求,但可能需要更多文件。以下代码采用文件名,但带有扩展名。我不要扩展名。谢谢你的帮助。
try
set theNames to {}
tell application "Finder"
repeat with i in (get selection)
set end of theNames to name of i
end repeat
end tell
set {TID, text item delimiters} to {text item delimiters, return}
set the clipboard to theNames as text
set text item delimiters to TID
end try
尝试此操作,而不是try块,脚本将检查是否为空选择,如果存在扩展名,则通过减去扩展名来提取fileName。
set theNames to {}
tell application "Finder"
set theSelection to selection
if theSelection is {} then return
repeat with anItem in theSelection
set {name:fileName, name extension:fileExtension} to anItem
set end of theNames to my removeExtension(fileName, fileExtension)
end repeat
end tell
set {TID, text item delimiters} to {text item delimiters, return}
set the clipboard to theNames as text
set text item delimiters to TID
on removeExtension(Nm, Ex)
if Ex is missing value or Ex is "" then return Nm
return text 1 thru ((count Nm) - (count Ex) - 1) of Nm
end removeExtension
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句