我想知道如何从字符串中返回文件扩展名。我已尝试在this问题中详细说明了'set variable to name extension of ...',但这似乎只适用于已识别的扩展。我们的想法是将扩展名为“.meta”的文件排序到自己的集合中。
我现在看起来像
tell application "Finder'
set everyName to name of every item in entire contents of this_folder
end tell
set metaFiles to {}
repeat with n from 1 to count of everyName
set currentName to item n of everyName
set currentExt to last word of currentName --this assignment fails
if currentExt is "meta" then
set end of metaFiles to currentExt
end if
end repeat
我对applecript很陌生,所以我感谢任何帮助/方向。谢谢!
编辑:Hacky解决方案
我通过使用描述here的分割函数来解决这个问题,以便在每个句点之后分解文件名。我抓住了最后一个字符串,确保它与第一个字符串不同,以防没有句点字符,然后存储相应的文件名。
答案 0 :(得分:1)
如果您没有获得名称扩展名,请确保确实存在名称扩展名,并且您没有查看名称的末尾。如果您要移动文件,您还需要获取路径,而不仅仅是名称。我不认为列出你的扩展列表是你想要的 - 或者几个不同的字符用于字边界,但句号不是其中之一。
为什么不向Finder询问您的文件?
tell application "Finder"
set metaFiles to (every item in entire contents of this_folder whose name extension is "meta") as alias list
end tell
答案 1 :(得分:1)
该名称包含文件扩展名,Finder是否识别它。所以只需按照这个名字排序......
tell application "Finder"
set metaFiles to (every item in entire contents of this_folder whose name ends with "meta") as alias list
end tell