AppleScript应用于文件夹名称的逻辑和原因是什么?猜猜这个剧本在做什么

时间:2016-09-14 21:47:40

标签: applescript directory finder

我偶然发现了我现场编程语言中最尴尬的一种行为。

猜猜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个数字并忽略零。请告诉我有一些合理的解释。或者这只发生在我身上......

1 个答案:

答案 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