我偶然发现了我现场编程语言中最尴尬的一种行为。
猜猜AppleScript正在做什么:
set workspace to "tmp"
set folder1 to "08_0000012_11"
set folder2 to "8_12_11"
tell application "Finder"
if (not (exists folder folder1 of (workspace as alias))) then
make new folder at workspace as alias with properties {name:folder1}
end if
if (not (exists folder folder2 of (workspace as alias))) then
make new folder at workspace as alias with properties {name:folder2}
else
log "Folder already exists " & folder2
end if
end tell
它应该在/ tmp内创建两个文件夹08_0000012_11和8_12_11,对吗? .....错了!它创建第一个并声称另一个已经存在。但事实并非如此!
似乎它试图将一些逻辑应用于这些名称。将它们拆分为3个数字并忽略零。请告诉我有一些合理的解释。或者这只发生在我身上......
答案 0 :(得分:0)
这是Finder中的一个错误。在排序文件名时,它应该只忽略前导零,比较它们时不。 File a bug report.
相同的逻辑在系统事件中正常工作,例如:
set fname to "001"
tell application "System Events"
if not exists folder fname of desktop folder then
make new folder at desktop folder with properties {name:fname}
end if
end tell