I a script, I want to access all the files in a folder that the user selects (choose folder)
The script is going to process folders with many files +10.000, each file is a JPG image that is processed.
The problem is that the script takes forever to even find all the files. I am using Finder to find the files
tell application “Finder” to set filelist to every item of entire contents of (choose folder) whose name ends with “.jpg”
I did some testing using my “Pictures” folder. There are 870 items in “every item of entire contents of” the folder, and 324 of them have file names ending in “.jpg”.
Here’s what I’ve found:
Using your method, it takes 28 seconds to do nothing but create the list of files whose name end in “.jpg”. So I decided to try getting every file and then using a repeat loop to determine if their name ends in “.jpg” like so:
Curious… Under similar conditions (about 800 items, nearly all ending in .jpg), your code runs here in 1000 ticks (aproximatelly 16 seconds), and the mine throws 5 ticks (0.08 seconds).
Here is the code (requires Jon’s Commands for “the ticks” calculation):
When I use the do shell script to find all my jpg files, it returns a list of items, but the string returned is not a correct folderitem (“/Users/mark/Documents/photomotion billeder//301120001.jpg”), you see the last two // before the filename ? Why is it not a correct path and how should I correct it.
I actually need the path as POSIX as I am uploading each item using CURL, but the path is obviously incorrect. How can I correct this ?
Cheers,
Mark
The double-backslash is not a problem.
About Jon’s Commands, there is also a X version (“Jon’s Commands X 3.0d3”). Pick it here: http://www.seanet.com/~jonpugh/
Use “-iname” instead of “-name” to make a case-insensitive search.
I repeat that the double-backslash is not a problem (though you can get ride off of it, if you wish, of course). Consider this:
set x to "/Users/john/Desktop//foo.txt"
POSIX file x
--> file "julifos:Users:john:Desktop:foo.txt"
Or this:
do shell script "mv /Users/john/Desktop//foo.txt /Users/john/Desktop/fooCOPY.txt"
--> OK
For more options in the “find” command, type “man find” in a Terminal window.