希望有人可以帮助我,
首先,我的AppleScript技能几乎不存在。
我以下列格式获取了许多用于归档的文件,这些文件需要排序。格式首先是设备名称,后跟运行编号和样本编号,后跟一些文本。
示例文件:“UZLA 55879 [05x13] 9月cal run.cdf”(文件格式各不相同) 需要将其移动到文件夹中:〜/ UZLA 55879(LCMS)/ Run 5 /
为了解决这个问题,我们希望在主驱动器上的单个文件夹中创建一个别名(文件移动到外部系统)以便直接访问,这很容易快速查看,但对整个系统来说完全不实用(其他脚本将旧的别名从中删除。)
感谢。
好吧,所以这是令人讨厌的关闭,因为它只会帮助我而不是未来的随机人。得到帮助对我来说有点重要。这就是我们所处的位置,感谢adayzdone:
set myFolder to (choose folder)
tell application "System Events" to set folderName to myFolder's name
set {TID, text item delimiters} to {text item delimiters, {"(", ")"}}
set myText to text item 2 of folderName
set text item delimiters to TID
set myFiles to every paragraph of (do shell script "find " & quoted form of (POSIX path of myFolder) & " \\! -name \".*\" -type f")
repeat with aFile in myFiles
set aFile to aFile as text
tell application "Finder" to set fileName to name of (POSIX file aFile as alias)
set newPath to "~/" & quoted form of (do shell script "echo " & quoted form of fileName & " | sed -e 's/\\[0/\\[/' -e 's/\\([^\\[]*\\)\\[\\([0-9]*\\)x[0-9]*\\].*/\\1(" & myText & ")\\/Run \\2\\//'") as text
do shell script "mkdir -p " & newPath & " ; mv " & quoted form of aFile & space & newPath
end repeat
这会出现以下错误:错误“无法获取\”testFolder \“的文本项2。”编号为-1728,来自“testFolder”的文本项目2
让我澄清一下:我在一个名为/ testFolder /的文件夹中有一堆文件(总是命名为,所有文件都在这里输入)我想要的是根据文件将文件移动到给定格式的文件夹和子文件夹中名。
示例:文件:/ UZLA 55879 [01x05] XXX.cdf
当前问题:该脚本现在尝试从起始文件夹中提取信息以选择目标文件夹,起始文件夹(未)命名为/ UZLA 55879(LCMS)/它使用“LCMS”创建目标文件夹。 (由于起始文件夹是1,它不能命名)和2))每个目标文件夹在这些括号之间有不同的项目(虽然有些相同),因此命名起始文件夹是没用的。该脚本使用“& myText&”,该字符串必须是一个随机字符串,由目标文件夹而不是起始文件夹定义。
答案 0 :(得分:0)
除非用户付出一些努力,否则我通常不会回答这样的问题,但我是正则表达式的傻瓜。
set sourceFolder to "/Users/You/Desktop/testFolder"
set destFolder to "/Users/You/Desktop/testFolder2"
set myFiles to every paragraph of (do shell script "find " & quoted form of sourceFolder & " \\! -name \".*\" -type f")
repeat with aFile in myFiles
set aFile to aFile as text
tell application "Finder" to set fileName to name of (POSIX file aFile as alias)
-- Find name of parent folder
set parentName to do shell script "echo " & quoted form of fileName & " | sed 's/ \\[.*//'"
tell application "System Events" to set parentFolder to POSIX path of (first folder of folder destFolder whose name starts with parentName)
-- Extract the text between ( and )
set myText to do shell script "echo " & quoted form of parentFolder & " | sed 's/.*(\\(.*\\)).*/\\1/'"
set newPath to quoted form of (destFolder & "/" & (do shell script "echo " & quoted form of fileName & " | sed -e 's/\\[0/\\[/' -e 's/\\([^\\[]*\\)\\[\\([0-9]*\\)x[0-9]*\\].*/\\1(" & myText & ")\\/Run \\2\\//'") as text)
do shell script "mkdir -p " & newPath & " ; mv " & quoted form of aFile & space & newPath
end repeat