我有2个文件夹
第一个文件夹包含我想移动到第二个文件夹的子文件夹的所有文件。我想根据文件和文件夹名称的前 7 个字符来做这个。
因此,如果 FOLDER 2 中子文件夹的前 7 个字符与 FOLDER 1 中文件的前 7 个字符匹配。文件 get 被移动到 FOLDER 2 的子文件夹中
现在我有一个可以工作的Applescript,但它非常慢。
这是到目前为止的脚本:
set mgFileList to ""
set mgDestFolder to ""
set mgFilesFolder to (choose folder with prompt "Where are the files stored which you would like to move to the destination?")
set mgDestFolder to (choose folder with prompt "Where is the destination folder?")
set folderList to contents of mgDestFolder
tell application "Finder" to set fileList to files of mgFilesFolder
repeat with aFile in fileList
set prefix to getPrefix(name of aFile)
tell application "Finder"
try
set destinationFolder to (1st folder of mgDestFolder whose name begins with prefix)
move aFile to destinationFolder
end try
end tell
end repeat
on getPrefix(aName)
set prefix to text 1 thru 7 of aName
return prefix
end getPrefix
我最近才接触到 Applescripting。这可以在 Applescript 中更有效地完成吗?我一直在寻找一种适用于 shell 脚本的解决方案(我认为它可能会快很多),但无法让它们中的任何一个工作。
我正在开发 OSX Mountain Lion 10.8.4
- 编辑
我看到我上传了错误版本的脚本,到目前为止我已经设法将它们放在一起。上面是正在运行的脚本,但它真的很慢。可能是因为它不使用任何 shell 脚本。
- - - - - - - -更新 - - - - - - - - - -
这是目前运行速度非常快的最终脚本:
set mgFilesFolder to choose folder with prompt "Where are the files stored which you would like to move to the destination?"
set mgDestFolder to choose folder with prompt "Where is the destination folder?"
tell application "System Events"
set fileList to files of mgFilesFolder whose name does not start with "."
repeat with aFile in fileList
set prefix to my getPrefix(name of aFile)
try
set destinationFolder to (1st folder of mgDestFolder whose name begins with prefix)
move aFile to POSIX path of destinationFolder
end try
end repeat
end tell
on getPrefix(aName)
try
set prefix to text 1 thru 7 of aName
return prefix
on error
return aName
end try
end getPrefix