RE: Problem getting files by file type or extension
RE: Problem getting files by file type or extension
- Subject: RE: Problem getting files by file type or extension
- From: Jim Skibbie <email@hidden>
- Date: Thu, 11 Dec 2008 12:00:48 -0600
- Thread-topic: Problem getting files by file type or extension
Title: RE: Problem getting files by file type or extension
I’ve had this same issue, especially working with remote volumes or folders with a large directory. I personally find the Finder very flaky and unreliable. You may want to try getting a list of the files using a shell command vs. the finder.
Something like:
set DirectoryListPath to POSIX path of (alias_to_whatever_directory)
set DirectoryList to every paragraph of (do shell script "ls " & quoted form of DirectoryListPath )
You could also narrow your search by piping a grep statement like:
set DirectoryList to every paragraph of (do shell script "ls " & quoted form of DirectoryListPath & " | grep '.crtr'")
However the grep is only going to find files by name, not by file type.
Once you have the list, you can loop through it to find the files that match your criteria:
set FinalList to {}
repeat with i from 1 to count of DirectoryList
set theFile to POSIX file (POSIX path of (DirectoryListPath & item i of DirectoryList))
set fileRecord to (info for theFile)
if (file type of fileRecord) is "Crtr" or (name extension of fileRecord) is "Crtr" then set FinalList to FinalList & ((theFile) as alias)
end repeat
This method is slower but extremely reliable over asking the Finder for this information, in my opinion.
Jim
I was wondering if this situation looks familiar to anyone, and if there's a known problem or workaround. I'm writing a script for a customer that batch processes documents stored in subfolders of a main folder. The script asks Finder for all MultiAd Creator documents like so:
set creatorFiles to (get every file of fold whose (file type is "Crtr" or name ends with ".crtr"))
"fold" is a Finder "folder" object reference. This line always works on my Mac. On the customer's Mac, it will seem to work for several subfolders, and then generate this error for some subfolders that - as far as I've been told - do have Creator documents in them:
Finder got an error: Can't make some data into the expected type.
"fold" is generated before the main loop by this line:
set fold to folder (get item i of foldNames) of mainFold
Again, this is using Finder objects, and both lines are within Finder tell blocks. The customer's OS is 10.3.9 (ewww). Mine's 10.5.5.
There might something that the customer isn't telling me, as I get the feeling he's not too swift (replies with one short answer when I asked three questions, says "Creator crashed" when what really happened was the script processed all subfolders and generated the appropriate error log, stuff like that).
Steve Mills
Drummer, Mac geek
http://sjmills5.home.mchsi.com/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden