File 如何使用AppleScript检查文件夹是否包含特定类型的文件?

File 如何使用AppleScript检查文件夹是否包含特定类型的文件?,file,applescript,File,Applescript,我和applescripting第一次编写了一个脚本,创建了一个.nfo文件,其中包含基于文件夹名的电影链接 当前,脚本设置为向用户请求包含其所有电影的文件夹,并在该文件夹中循环,直到处理完所有子文件夹 结构如下: 电影 电影一 视频文件 电影1.nfo 电影2 视频文件 电影2.nfo 电影3 视频文件 电影3.nfo 等等 我需要帮助添加一个if-then-else语句,该语句首先检查一个nfo文件是否已经存在,如果已经存在,只需增加计数器即可移动到下一个文件夹,或者运行

我和applescripting第一次编写了一个脚本,创建了一个.nfo文件,其中包含基于文件夹名的电影链接

当前,脚本设置为向用户请求包含其所有电影的文件夹,并在该文件夹中循环,直到处理完所有子文件夹

结构如下:

  • 电影
    • 电影一
      • 视频文件
      • 电影1.nfo
    • 电影2
      • 视频文件
      • 电影2.nfo
    • 电影3
      • 视频文件
      • 电影3.nfo
等等

我需要帮助添加一个if-then-else语句,该语句首先检查一个nfo文件是否已经存在,如果已经存在,只需增加计数器即可移动到下一个文件夹,或者运行我当前的脚本代码

我试过像这样的东西

if (theFiles contains files whose name extension is nfo) then
    i = i + 1
else
    -- My Code
end if
它似乎并不在意,只是再次处理所有文件夹,用新文件夹替换当前的nfo

当前应用程序脚本:

property imdburl : ""
property newurl : ""
property FolderPath1 : ""
property FolderPath : ""
property Foldername : ""

tell application "Finder"
    activate
    set theFolder to choose folder with prompt "Select the Movie Folder."
    set theList to every folder of theFolder
    repeat with i from 1 to count the theList
        set thisItem to item i of theList as alias
        set currentName to name of thisItem
        --set currentfolder to get the POSIX path of thisItem
        set theFiles to every file of folder thisItem as alias list

        if (theFiles contains files whose name extension is nfo) then
            i = i + 1
        else
            tell application "Finder"
                set FolderPath1 to thisItem -- sets file path to folder you select
                set ParentFolder to container of FolderPath1 -- sets the parent folder of the folder you select
                set Foldername to name of folder FolderPath1 -- sets the folder name as text
                set FolderPath to get the POSIX path of FolderPath1
                set newurl to "http://google.com/search?q=" & Foldername & "+imdb&btnI=I%27m+Feeling+Lucky"
                --set the clipboard to newurl -- sets foldername to the clipboard
            end tell

            tell application "Safari"
                open location newurl
                activate
                delay 3
                set imdburl to URL of current tab of window 1
                set the clipboard to FolderPath
                close window 1
            end tell

            tell application "TextEdit"
                activate
                make new document
                set text of document 1 to imdburl
                set Foldername to text 1 thru -(7 + 1) of Foldername
                save document 1 in FolderPath & "/" & Foldername
                close document 1
            end tell

            tell application "Finder" to set name extension of (files of FolderPath1 whose name extension is "rtf") to "nfo"
        end if
    end repeat
end tell

此示例演示如何检查文件夹中的应用程序包(只是为了便于测试)。将.app替换为.ifo,您就拥有了所需的内容

on foo()
    tell application "Finder"
        set someFolder to choose folder
        set aList to name of files of someFolder as list
        set AppleScript's text item delimiters to return
        return ".app" is in (aList & return as text)
    end tell
end foo

on run {}
    foo()
end run

请注意,与通常所述相反,获取文件夹的文件列表不需要重复循环。

必须将其作为一个分支点,以使if语句工作
将列表设置为该项的文件名,将列表设置为CurrentInfo到currentName的文本1到-(7+1),如果(CurrentInfo&“.Info”在(列表中))然后i=i+1表示此方法不适用于隐藏的查找器项,例如
.git
文件夹,除非显式更改查找器配置以显示此类项。