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: Thu, 10 Jan 2002 12:45:16 +0000
"Wadson, David" wrote on Wed, 9 Jan 2002 15:50:39 -0500 :
>
A list of files named:
>
>
A1...plus some other characters
>
A10...plus some other characters
>
A11...plus some other characters
>
A12...plus some other characters
>
A2...plus some other characters
>
A3...plus some other characters
[...]
>
>
Two problems - there will be other files in the list named started with B1,
>
B2,... C1, C2,...etc. I also won't know how many files will start with "A" -
>
there could be 8, 10, or 12 files.
>
>
I need to process each file in numerical order. By using a simple loop
>
incrementing from 1 to however many files I have, I've been selecting the
>
appropriate files by looking for the the files that "starts with A2", or
>
"starts with A3". But if I'm searching for the page that starts with "A1", I
>
also get pages "A10", "A11" and "A12".
I'm not quite sure about the following script. It relies on the fact that
the Finder returns file names in alphabetical order on my system. (I
don't know if this is universally true.) It also assumes that the numbers
in the names won't be higher than 99. It sorts the names of a folder's
files into the order you require.
set myFolder to choose folder
set sortedList to {}
set theLetters to "ABCDE" -- or as required
set theDigits to "0123456789"
repeat with i from 1 to (count theLetters)
set thisLetter to character i of theLetters
try -- in case no names begin with this letter
tell application "Finder"
-- The Finder returns the names in alphabetical order on my system
set nameList1 to (name of files of myFolder whose name begins
with thisLetter)
end tell
-- Separate the high- and low- number names
-- and add them to the final list
set hiList to {}
repeat with thisName in nameList1
if thisName's length is greater than 2 and thisName's character 3
is in theDigits then
set end of hiList to thisName's contents
else
set end of sortedList to thisName's contents
end if
end repeat
set sortedList to sortedList & hiList
on error
end try
end repeat
sortedList
-- A list of all the file names, sorted as required
NG