2013-04-18 3 views
0

Первый раз, когда я написал applescripting, и я собрал скрипт, который создает файл .nfo, содержащий ссылку IMDB на фильм по имени папки.Как проверить, содержит ли папка определенный тип файла с AppleScript?

В настоящее время сценарий настроен на то, чтобы спросить пользователя о папке, которая содержит все их фильмы, и она обходит эту папку до тех пор, пока все подпапки не будут обработаны.

Структура:

  • Фильмы
    • фильм 1
      • Видеофайл
      • фильм 1.nfo
    • фильм 2
      • видео файл
      • фильм 2.nfo
    • фильм 3
      • видео файл
      • фильм 3.nfo

и так далее ...

Мне нужна помощь addi ng оператор if-then-else, который сначала проверяет, присутствует ли файл nfo, и если он есть, просто увеличьте счетчик, чтобы перейти к следующей папке, или запустите мой текущий код сценария.

Я попытался вещи, как

if (theFiles contains files whose name extension is nfo) then 
    i = i + 1 
else 
    -- My Code 
end if 

Это, кажется, не волнует, и просто обрабатывает все папки снова заменяя текущий NFO с новым.

Текущий AppleScript:

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 

ответ

0

В этом примере показано, как проверить наличие пакета прикладных программ в папке (только, чтобы сделать это легко проверить). Замените .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 

Обратите внимание, что вопреки тому, что часто указывается, цикл повторения не требуется для получения списка файлов в папке.

+0

пришлось использовать это как ответвление от точки, чтобы получить, если заявление на работу
набор ALIST для имени файлов thisItem в виде списка \t \t набор currentnfo к тексту 1 через - (7 + 1) из currentName \t \t если (currentnfo & «.nfo» находится в (крене)), то \t \t \t я = я +- \t \t – user2296273

+0

еще Обратите внимание, что этот подход не будет работать со скрытыми элементами Finder, такими как, например, '.git', если для отображения таких элементов явно не изменена конфигурация Finder. – ssc

Смежные вопросы