我已经完成了这个脚本,它根据前6个字符串将文件组织到子文件夹中。
例如,bjaaahdd_123
将位于名为"bjaaahd"
的子文件夹中。
此脚本在虚拟文件上进行了测试,以检查其可行性。
但现在,试着测试真正的任务。它没有按预期工作。
文件格式为"_londondire_123455-901-34"
等。
我希望“_londondire”部分只是该文件夹并按该名称组织。换句话说,只有没有数字的名称。 我读到了分隔符,但是对于上帝的爱,我不明白。
--script begins
on run
set theFolder to ""
set fileList to {}
set theTarget to ""
set theString to ""
tell application "Finder"
set theFolder to (choose folder with prompt "Choose containing folder:" without invisibles and multiple selections allowed)
set fileList to every file of theFolder
repeat with i in fileList
name of i as text
set theString to text 1 thru 6 of result
try
set theTarget to ((theFolder as text) & theString) as alias
move i to theTarget
on error
make new folder at theFolder with properties {name:theString}
move i to result
end try
end repeat
end tell
end run
--script ends
我怎样才能做到这一点?
答案 0 :(得分:0)
text item delimiters
是最好的方法。
使用此代码
set theText to "_londondire_123455-901-34"
set {TID, text item delimiters} to {text item delimiters, "_"}
set textItems to text items of theText
set text item delimiters to TID
变量textItems
中的结果是列表{"", "londondire", "123455-901-34"}
,因此所需的值是第二个文本项
set theResult to item 2 of textItems -- "londondire"
如果您需要前导下划线写
set theResult to "_" & item 2 of textItems -- "_londondire"