This is a follow-up to yesterday's comments. I was curious just how fast one could count the files in a folder. I hadn't yet tried System Events, so I created a test folder containing 532 files and compiled each of these scripts to an applications with ASE ...
on open dropList if (count items of dropList) > 1 then return set folderAlias to (item 1 of dropList) as alias tell application "Finder" to if (class of item folderAlias) is not folder then return set elapsedTime to (current date) -- tell application "System Events" set folderList to (every disk item of folderAlias whose visible is true) end tell -- set elapsedTime to ((current date) - elapsedTime) set itemCount to (count items of folderList) "items = " & itemCount & return & "time = " & elapsedTime & " sec" display dialog the result buttons {"OK"} default button 1 end open
on open dropList if (count items of dropList) > 1 then return set folderAlias to (item 1 of dropList) as alias tell application "Finder" to if (class of item folderAlias) is not folder then return set elapsedTime to (current date) -- tell application "Finder" set folderList to (files of folderAlias) end tell -- set elapsedTime to ((current date) - elapsedTime) set itemCount to (count items of folderList) "items = " & itemCount & return & "time = " & elapsedTime & " sec" display dialog the result buttons {"OK"} default button 1 end open
on open dropList if (count items of dropList) > 1 then return set folderAlias to (item 1 of dropList) as alias tell application "Finder" to if (class of item folderAlias) is not folder then return set elapsedTime to (current date) -- set folderList to do shell script "ls " & quoted form of (POSIX path of folderAlias) -- set elapsedTime to ((current date) - elapsedTime) set AppleScript's text item delimiters to {return} set itemCount to (count text items of folderList) "items = " & itemCount & return & "time = " & elapsedTime & " sec" display dialog the result buttons {"OK"} default button 1 end open
And the results: ls --------------> about 1 sec Finder -----------> 10 sec System Events ----> 26 sec
If you double the size of the test folder, Finder and System Events simply render the system inoperable. You'll have to restart. 'ls' on the other hand seems not to care about the size of the test folder.
|