@Homer712 just a little friendly advice for you…
Finder is painfully slow in dealing with lists of files and folders. (and considerably worse as the lists get larger and larger) Try using System Events to deal with files and folders instead of Finder, whenever you can.
Continuing to use Finder like you are doing sometimes creates huge bottle-necks and sooner or later you will probably find your scripts error out because the Finder code timed out. Then you will have to start wrapping your Finder code within a with timeout of ... seconds
clause because the default time out is only 120 seconds.
To demonstrate exactly what I’m talking about, I created a folder on my Desktop named “Test”. Then I created 5000 text files within that folder. This following AppleScript code will create that folder and files for you if you want to run some of your own testing.
set theFolder to (path to desktop as text) & "Test"
try
alias theFolder -- checks if folder ~/Desktop/Test exists
on error errMsg number errNum -- If folder ~/Desktop/Test doesn't exist, creates ~/Desktop/Test folder and 5000 .txt files in it
do shell script "mkdir ~/Desktop/Test ;cd ~/Desktop/Test ;touch File_{0001..5000}.txt"
end try
Then I used Finder then System Events to simply get the list of files with in that folder and I compared their timing results.
As you can see, Finder was generally 14 times slower.
Honestly though, for this kind of project, personally I would not use Finder or System Events. I would use the do shell script "find "
command to retrieve the file list. (which is 25 times faster than using System Events)
If you use the code I posted above to create the “Test” folder with the 5000 text files in it, on your Desktop, here is all of the code I used to run the tests and you can check for yourself.
set theFolder to (path to desktop as text) & "Test"
tell application "Finder"
set theFiles to (files of alias theFolder) as alias list
end tell
And…
set theFolder to (path to desktop as text) & "Test"
tell application "System Events"
set theFiles to (path of items of alias theFolder)
end tell
And…
set theFiles to paragraphs of ¬
(do shell script "cd ~/Desktop/Test ;find \"$PWD\" -type f -mindepth 1 -maxdepth 1 |sort -f")