2011-11-28 44 views
1

我想知道如何从字符串中只返回文件扩展名。我已经尝试过'设置变量扩展名...',在this问题中有详细说明,但这似乎只适用于公认的扩展。这个想法是将文件扩展名为'.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 

我的品牌新的AppleScript所以我明白任何和所有帮助/方向。谢谢!

编辑:哈克解决方案

我通过使用分割功能解决了这个描述here每一个时期后,打破了文件名。我抓住最后一个字符串,确保它与第一个字符串不相同,以防没有句点字符,然后存储相应的文件名。

回答

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 
+0

试了一遍,完全有效,我是个白痴。谢谢! – Tuck

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 
+0

的“元”扩展名是如你所说,所以搜索不都把“元”扩展为有效的名称只是一部分,不填写metaFiles列表。但是,我正在外部传递这些文件,并且无法修改它们以具有适当的扩展名。 – Tuck

+0

如果没有扩展名,测试可以用于名称中的其他事物,比如名称以“meta”结尾,由regulus6633发布 – 2011-11-28 23:34:12