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 
    ... 

先のファイル構造:あなたは、残念ながら、時には2つのフォルダを見ることができるように

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

Thats it !!

オリジナルのスクリプトを編集してもうまく動作しますが、あなたの方がよりエレガントで、おそらくより高速です。どうもありがとうございました!

ここに私のバージョン:

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 
関連する問題