2017-03-31 3 views
0

3 단계 깊이의 폴더가 있으며 각 수준에는 많은 양의 파일이 있습니다. 나는 아래 스크립트로 2 단계의 깊이를 얻을 수 있지만, 3 단계는 약간의 도전을 제기하고 있습니다. 어떤 사람이 내가 한 단계 더 깊숙이 들어가야한다는 것에 관해 어떤 조언을 해 주시겠습니까? 파이썬이나 다른 언어를 사용하는 것은 용납되지 않을 것입니다. AppleScript로 이것이 어떻게 작동하는지 보려고합니다.Deeper In Recursive Processing

set sourceFolder to (choose folder) 

tell application "Finder" 
    my changeFileNameCase(sourceFolder, "upper") 
    repeat with subFolder in (get every folder of folder sourceFolder) 
     my changeFileNameCase(subFolder as alias, "upper") 

     #This Is No Good 
     repeat with theFolder in (get every folder of folder subFolder) 
      my changeFileNameCase(theFolder, "upper") 
     end repeat 

    end repeat 
end tell 

on changeFileNameCase(targetFolder, caseToSwitchTo) 
    tell application "Finder" 
     set fileList to every file of folder targetFolder 
     repeat with theFile in fileList 
      set oldName to name of theFile 
      set newName to my changeCaseOfText(oldName, caseToSwitchTo) 
      set the name of theFile to newName 
     end repeat 
    end tell 
end changeFileNameCase 

답변

2

처리기를 재귀 적으로 만들려면 폴더의 모든 항목을 가져 와서 각 항목의 클래스를 확인해야합니다.

  • 클래스가 folder 전화 폴더를 통과하는 핸들러의 경우 클래스는
  • 경우 file

set sourceFolder to (choose folder) 
changeFileNameCase(sourceFolder, "upper") 

on changeFileNameCase(targetFolder, caseToSwitchTo) 
    tell application "Finder" 
     set theList to every item of targetFolder 
     repeat with i from 1 to count theList 
      set theItem to item i of theList 
      if class of theItem is folder then 
       my changeFileNameCase(theItem, caseToSwitchTo) 
      else 
       set oldName to name of theItem 
       set newName to my changeCaseOfText(oldName, caseToSwitchTo) 
       set name of theItem to newName 
      end if 
     end repeat 
    end tell 
end changeFileNameCase 
+0

아, 나는 거의이 함께 어디로 가는지 참조 이름을 변경 그러나 theItem이 폴더 인 것처럼 보이면이 폴더의 이름을 바꿀 것입니다. 여기서 파일의 이름을 바꾸려고합니다. 나는 서브 폴더의 목록을 만들어야 할 곳을 가정하고 있습니까? theItem이 폴더 인 경우 - 하위 폴더 목록을 작성 하시겠습니까? – Jesse

+0

아니요, 항목이 폴더 인 경우 처리기를 재귀 적으로 호출합니다. 레벨 수는 중요하지 않습니다. – vadian

+0

둘째로, 나는 핸들러가 스스로를 호출하는 것을 본다. 어쨌든 자체 호출 오류에서 "오류가 발생했습니다 : 오류가 발생했습니다 : changeFileNameCase를 계속할 수 없습니다." number -1708 나는이 시간을 따로 쓴다. – Jesse