简体   繁体   English

Applescript将文件复制到特定文件夹

[英]Applescript copy files to specific folders

I want to copy files to specific folders. 我想将文件复制到特定的文件夹。 The folder names and the file names have the first 14 characters in common. 文件夹名称和文件名称的前14个字符相同。 This is my folder structure: 这是我的文件夹结构:

The Source File Structure: 源文件结构:

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

The Destination File Structure: 目标文件结构:

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

As you can see unfortunately sometimes two folders begin with the same folder name (but are distinguished by the random digits that follow) 如您所见,不幸的是,有时两个文件夹以相同的文件夹名称开头(但以后面的随机数字来区分)
I managed to put together the following script: 我设法整理了以下脚本:

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

The script works - but right now I have to choose my source and destination folder for every folder A001, A002 etc. It would be more convenient to be able to choose the top-level folders as source (Folder Proxy) and destination (Folder FullRes). 该脚本有效-但现在我必须为每个文件夹A001,A002等选择我的源文件夹和目标文件夹。能够选择顶级文件夹作为源(文件夹代理)和目标(文件夹FullRes)会更方便。 )。 How can I do that? 我怎样才能做到这一点?

Thats it!! 而已!!

I edited my original script and it works as well, but yours is way more elegant and probably faster. 我编辑了原始脚本,它也可以正常工作,但是您的脚本更优雅,而且速度可能更快。 Thank you very much! 非常感谢你!

Here my version: 这是我的版本:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM