Re: Differentiating between "A1", "A12", "A13"
Re: Differentiating between "A1", "A12", "A13"
- Subject: Re: Differentiating between "A1", "A12", "A13"
- From: Nigel Garvey <email@hidden>
- Date: Sun, 13 Jan 2002 16:08:48 +0000
Arthur J Knapp wrote on Fri, 11 Jan 2002 16:44:14 -0500:
>
>>> From: Nigel Garvey <email@hidden>
>
>
>>> -- Get the names of all the files in the folder
>
>>> -- (Hopefully, they're in alphabetical order)
>
>>
>
>>> tell application "Finder" to set nameList1 to name of files of myFolder
>
How about a hack:
>
>
tell application "Finder"
>
set theFolder to choose folder
>
set theFiles to sort (every file of theFolder) by name
>
end tell
>
>
set theNames to FilenamesFromFinderObjects(theFiles)
>
>
on FilenamesFromFinderObjects(aFiles)
>
>
try
>
err of aFiles
>
on error str
>
end try
>
>
set text item delimiters to {"file \""}
>
set str to str's text items
>
set text item delimiters to {"\""}
>
>
set aNames to {}
>
repeat with x from 2 to str's length
>
>
-- Faster than sending AppleEvents for each file.
>
--
>
set aNames's end to str's item x's text item 1
>
>
end repeat
>
>
return aNames
>
>
end FilenamesFromFinderObjects
Thanks for that, Arthur! I'm still not sure if 'name of files of ...'
*always* returns an alphabetically sorted list, as per my assumption
above, or not. 'Items of' produces anomalies when applied to my startup
disks or system folders, but works alphabetically on all the other
folders I've tried. But your handler's fast enough to make sure of the
situation without taking taking noticeably longer - let alone all day.
And it's also good for getting the names of files sorted on other
criteria, if need be.
For my own use, I've forced the return of plain text (probably
unnecessarily):
try
err of aFiles
on error str -- str is styled text (the user's AppleScript formatting)
end try
set text item delimiters to {"file \""}
set str to (str as Unicode text as string)'s text items
I've also reset the delimiters to {""} after the repeat. (I know you
creative types don't always have time for such petty details.) ;-)
Thanks again.
NG