【问题标题】:Applescript copy files to specific foldersApplescript 将文件复制到特定文件夹
【发布时间】:2018-05-17 18:29:18
【问题描述】:

我想将文件复制到特定文件夹。文件夹名和文件名的前 14 个字符相同。 这是我的文件夹结构:

源文件结构:

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)。我该怎么做?

【问题讨论】:

    标签: file copy applescript directory move


    【解决方案1】:

    就是这样!!

    我编辑了我的原始脚本,它也可以工作,但你的更优雅,可能更快。非常感谢!

    这是我的版本:

    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
    

    【讨论】:

      猜你喜欢
      • 2010-10-28
      • 2011-06-12
      • 1970-01-01
      • 1970-01-01
      • 2018-12-27
      • 2020-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多