【发布时间】:2018-03-15 17:41:17
【问题描述】:
我有一个目标文件夹中的文件列表:
示例/HUVEC.csv
示例/HUVEC-1.csv
示例/HUVEC-3.3.2n-1.csv(随机散列)
示例/Endo1.csv
如果“示例”文件夹中有以“HUVECxxx”开头的文件,我希望能够创建一个名为“HUVEC”的文件夹,然后将“HUVECxxx”开头的文件移动到“ HUVEC”文件夹。
这是我目前所拥有的,已从简单版本修改(见下文)
set mgFilesFolder to choose folder with prompt "Where are the files stored which you would like to move to the destination?"
tell application "Finder"
set fileList to files of mgFilesFolder
repeat with aFile in fileList
set prefix to name of aFile
if prefix starts with "HUVEC" and (exists folder (HUVEC_folder)) then
move aFile to HUVEC_folder
else
set HUVEC_folder to make new folder in mgFilesFolder with properties {name:"HUVEC"}
end if
end repeat
repeat with aFile in fileList
set prefix to name of aFile
if prefix starts with "HUVEC" then move aFile to HUVEC_folder
end repeat
end tell
更简单的版本适用于一个文件
set mgFilesFolder to choose folder with prompt "Where are the files stored which you would like to move to the destination?"
tell application "Finder"
set fileList to files of mgFilesFolder
repeat with aFile in fileList
set prefix to name of aFile
if prefix starts with "HUVEC" and set HUVEC_folder to make new folder in mgFilesFolder with properties {name:"HUVEC"}
end if
end repeat
repeat with aFile in fileList
set prefix to name of aFile
if prefix starts with "HUVEC" then move aFile to HUVEC_folder
end repeat
end tell
但是我很确定多个文件的问题是,如果文件夹已经存在,那么脚本就会失败。
基本上我认为最大的问题是如何检查一个文件夹是否存在,否则应该创建!
感谢您的帮助,在 Applescript 中仍然相对较新。
【问题讨论】:
标签: macos applescript