2017-12-04 33 views
0

파일을 특정 폴더에 복사하고 싶습니다. 폴더 이름과 파일 이름은 처음 14자를 공통으로 포함합니다. 이 내 폴더 구조 :AppleScript로 특정 폴더에 파일 복사

소스 파일 구조 :

Proxy 
    RED_A001_0101R7 (the last 6 digits are random) 

      A001_C001_0101RN_001_Proxy.mp4 (video file to be copied) 
      A001_C002_0101D5_001_Proxy.mp4 (video file to be copied)         
          ... 
    RED_A001_0525A1 
    RED_A002_010107 
    ... 

대상 파일 구조 :

FullRes 
    RED_A001_0101R7 
      A001_C001_0101RN.RDC (Folder in which the correct _Proxy file should be copied in) 
      A001_C002_0101D5.RDC (Folder in which the correct _Proxy file should be copied in) 
        ... 
    RED_A001_0525A1 
    RED_A002_010107 
    ... 

가끔 두 개의 폴더가 (같은 폴더 이름으로 시작 불행하게도 볼 수 있듯이 뒤에 나오는 임의의 숫자로 구별됩니다)
다음 스크립트를 함께 관리했습니다 :

set ProxyFolder to (choose folder with prompt "Choose the Source Folder") 
set FullresFolder to (choose folder with prompt "Choose the Destination Folder") 

tell application "System Events" 
     set folderList to name of folders of FullresFolder 
     set fileList to name of files of ProxyFolder 
end tell 

repeat with i from 1 to (count folderList) 
     set folderName to item i of folderList 
     set beginFolderName to text items 1 thru 14 of folderName 
     set filesToMove to {} 
      repeat with j from 1 to (count fileList) 
        set filename to item j of fileList 
        if filename begins with beginFolderName then 
         set end of filesToMove to alias ((ProxyFolder as string) & filename) 
        end if 
      end repeat 

tell application "Finder" 
        duplicate filesToMove to alias ((FullresFolder as string) & folderName & ":") 
     end tell 
end repeat 

스크립트가 작동하지만 - 지금은 모든 폴더 A001, A002 등의 소스 및 대상 폴더를 선택해야합니다. 소스 (폴더 프록시)로 최상위 폴더를 선택할 수있는 것이 더 편리 할 것입니다. 및 대상 (폴더 FullRes). 어떻게해야합니까?

답변

0

그게 전부 !!

제 원래 스크립트를 편집했는데 잘 작동하지만 당신의 방식은 훨씬 더 우아하고 더 빠릅니다. 고마워요! 여기

내 버전 :

set topLevelProxyFolder to (choose folder with prompt "Choose the PROXY Folder") 
set topLevelFullresFolder to (choose folder with prompt "Choose the FULL RES Folder") 

tell application "System Events" 
    set folderList to name of folders of topLevelFullresFolder 
    set proxyFolderList to name of folders of topLevelProxyFolder 
end tell 

set allFilesList to {} 

repeat with thisProxyFolder from 1 to (count proxyFolderList) 
    set thisProxyFolderName to item thisProxyFolder of proxyFolderList 
    set thisSubProxyFolder to alias ((topLevelProxyFolder as string) & thisProxyFolderName) 

    tell application "System Events" 
     set thisFileList to name of files of thisSubProxyFolder 
    end tell 

    set allFilesList to allFilesList & thisFileList 

end repeat 

repeat with thisFolder from 1 to (count folderList) 
    set thisFolderName to item thisFolder of folderList 
    set thisSubFolder to alias ((topLevelFullresFolder as string) & thisFolderName) 

    tell application "System Events" 
     set subFolderList to name of folders of thisSubFolder 
    end tell 

repeat with i from 1 to (count subFolderList) 
    set thisSubFolderName to item i of subFolderList 
    set beginSubFolderName to text items 1 thru ((get offset of "." in thisSubFolderName) - 1) of thisSubFolderName 
    set filesToMove to {} 

    repeat with j from 1 to (count allFilesList) 
     set fileName to item j of allFilesList 
     if fileName begins with beginSubFolderName then 
      set end of filesToMove to alias ((topLevelProxyFolder as string) & thisFolderName & ":" & fileName) 
     end if 

    end repeat 

    tell application "Finder" 
     duplicate filesToMove to alias ((topLevelFullresFolder as string) & thisFolderName & ":" & thisSubFolderName & ":")   
    end tell 

    end repeat 
end repeat