[英]Applescript copy files to specific folders
我想將文件復制到特定的文件夾。 文件夾名稱和文件名稱的前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)會更方便。 )。 我怎樣才能做到這一點?
而已!!
我編輯了原始腳本,它也可以正常工作,但是您的腳本更優雅,而且速度可能更快。 非常感謝你!
這是我的版本:
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.