2017-11-01 16 views
0

질문이 있습니다. 기본적으로 AppleScript로 "application"을 썼는데, 뭔가 의심 스럽습니다.Q : Applescript - 폴더에있는 모든 파일을 전달하지 않습니다.

tell application "Finder" 

    activate 

    set theXMLFolder to choose folder with prompt "ok" 

    set numberOfFiles to count of (files in folder theXMLFolder) 

    repeat with a from 1 to numberOfFiles 

     set theXMLFile to item a of theXMLFolder 

     if name extension of theXMLFile is in validExtensions then 

      my resetVariables() 

      my importXMLFolder(theXMLFile as string) -- import and read XML file 

      my writeToExcel() -- convert XML to Excel file 

     end if 

    end repeat 

end tell 

이것은 폴더 안에 XML 파일을 묻는 메시지입니다. 문제는 폴더에 XML 파일 만 있으면 완벽하게 작동하지만 순간에는 다른 파일이있을 수 있습니다. 가끔은 모든 파일을 읽을 수없는 경우가 있습니다. 9 개의 파일 중 7 개만 찾습니다. 항상 모든 파일을 볼 수있는 방법이 있습니까? 감사합니다

답변

0

이것은 당신이를 우회 할 수이 코드 시에라

의 최신 버전에 나를 위해 작동 전체 "조건부"코드 부분

property nameExtension : "xml" 

set theXMLFolder to choose folder with prompt "ok" 

tell application "Finder" 
    set theFiles to files of theXMLFolder whose name extension is nameExtension 
    repeat with i from 1 to number of items in theFiles 
     set theXMLFile to item i of theFiles 

     my resetVariables() 
     my importXMLFolder(theXMLFile as string) 
     my writeToExcel() 

    end repeat 
end tell 
0

다음 애플 스크립트 코드는 파일 예를 들어, name extensionvalidExtensions을 설정할 필요에 작용 xml하고 repeat루프에 무엇을 기반으로 모든 xml 파일에 따라 행동 할 것이다는 -- # Do something. 즉 :

set validExtensions to {"xml"} 
tell application "Finder" 
    set theXMLFolder to choose folder with prompt "Select the folder containing the xml files:" 
    repeat with i from 1 to (count of files in folder theXMLFolder) 
     set theXMLFile to item i of theXMLFolder 
     if name extension of theXMLFile is in validExtensions then 
      -- # Do something. 
      log (get name of item i of folder theXMLFolder) 
     end if 
    end repeat 
end tell