2017-05-01 15 views
0

폴더를 자동으로 만들고 다음 첫 번째 숫자를 기반으로 파일을 정렬하는 폴더를 만들려고합니다. 정렬해야하는 파일은 모두 2 월 4 2.3 U # 03 (3) .mrd과 같은 형식으로 나타납니다. 내 의도는 AppleScript를 써서 숫자 (2.3)를 기반으로 폴더를 만든 다음 (2.3)을 포함한 모든 파일을 해당 폴더에 넣고 다른 모든 파일과 동일하게 작성하는 것이 었습니다. AppleScript를 사용하여 첫 번째 숫자를 기준으로 새 폴더에 파일 정렬

나는 작동하는 것 같다 그들의 수를 기준으로 파일을 정렬 조금

set text item delimiters to {" "} 
tell application "Finder" 
    set aList to every file in folder "Re-namer" 
    repeat with i from 1 to number of items in aList 
    set aFile to (item i of aList) 
    try 
     set fileName to name of aFile 
     set firstPart to text item 1 of fileName 
     set secondPart to text item 2 of fileName 
     set thirdPart to text item 3 of fileName 
     set fourthPart to text item 4 of fileName 
     set fifthPart to text item 5 of fileName 
     set newName to thirdPart & " " & secondPart & " " & firstPart & " " & fourthPart & " " & fifthPart 
    set name of aFile to newName 
    end try 
end repeat 
end tell 

지금 난 그냥 첫 번째 숫자에 따라 새 폴더를 만들고에 일치하는 파일을 둘 필요했다. I를 이것에 대한 스크립트가 너무 만들려고 (내가 전에 코딩 적이 명심하고 내가 뭘하는지 아무 생각이 없음) 및 당연히 작동하지 않았다 :(

tell application "Finder" 
open folder "Re-namer" 
set loc to folder "Re-namer" 
set aList to every file in loc 
repeat with i from 1 to number of items in aList 
    set aFile to (item i of aList) 
    if not (exists folder named "text item 1" in loc) then 
     make new folder in loc with properties {name:"text item 1"} 
    else 
     move aFile in folder "text item 1" 
    end if 
end repeat 
end tell 

을 내가 몇 가지를 발견했습니다 비슷한 질문이지만 여전히 작동하도록 할 수는 없습니다. 누구든지이 질문에 도움이되는 아이디어 나 자원이 있다면 나는 크게 그것을 appreaate 것입니다.

+0

당신의 접근 방식은 초급자에게 좋습니다. 오픈 폴더 "리 네이머"라고 말하는 대신 그 폴더에 대한 경로를 제공해야합니다. 나는 그것에 대한 언급을 보지 못했다. –

답변

0

귀하는 매우 정확한 스크립트에 가깝습니다. 그러나 이름을 변경하고 파일을 이동하는 두 개의 루프를 수행하는 대신 한 번에 둘 다 수행하는 것이 더 빠릅니다.

또한 중요한 점은 루프에서 이름을 변경하면 Finder에서 변경된 파일에 대한 참조가 느슨해 지므로 이름을 변경 한 후 파일을 이동하려고하면 파일이 이동하지 않는다는 점입니다. 폴더와 새 이름을 알고 있기 때문에 "새"파일을 계속 참조 할 수 있습니다.

set MyRenamer to choose folder "Select the folder" 
set TPath to MyRenamer as string 
set text item delimiters to {" "} 
tell application "Finder" 
    set aList to every file in MyRenamer 
     repeat with F in aList 
     set fileName to name of F 
     set firstPart to text item 1 of fileName -- like "Feb" 
     set secondPart to text item 2 of fileName -- like "4" 
     set thirdPart to text item 3 of fileName -- like "2.3" 
     set fourthPart to text item 4 of fileName -- like "U#03" 
     set fifthPart to text item 5 of fileName -- like "(3).mrd" 
     set newName to thirdPart & " " & secondPart & " " & firstPart & " " & fourthPart & " " & fifthPart 
     set name of F to newName 
     if (not (exists folder thirdPart in MyRenamer)) then 
      make new folder in MyRenamer with properties {name:thirdPart} 
     end if 
     move (TPath & newName) as alias to folder (TPath & thirdPart & ":") -- rebuild the new file path as alias and move it. 
    end repeat 
end tell 

테스트 완료 및 확인.

+0

그것은 매우 도움이됩니다, 정말 고마워요! – Matt