Applescript获取没有扩展名的文件名

时间:2017-01-04 10:43:53

标签: applescript

我想在扩展名为mp4或mov的文件夹中没有扩展名的文件,并将其放入变量中。在这个文件夹中,文件是mulitple文件,但只有一个在mp4或mov。

现在,这就是我所拥有的:

set _ext to {"mp4", "mov"}
set _folder to "path_folder"

tell application "Finder"
   set _name to name of every file of _folder whose name extension is in "_ext"
end tell

任何人都可以提供帮助吗?

1 个答案:

答案 0 :(得分:0)

脚本中还有其他一些问题,请尝试此问题。它使用更多描述性变量名称,变量baseName包含结果,文件名不包含扩展名。

set allowedExtensions to {"mp4", "mov"}
set targetFolder to "path_folder"

tell application "Finder"
    try
        set {name:fileName, name extension:fileExtension} to first file of folder targetFolder whose name extension is in allowedExtensions
        set baseName to text 1 thru ((get offset of "." & fileExtension in fileName) - 1) of fileName
    on error
        display dialog "File not found" buttons {"Cancel"} default button 1
    end try
end tell