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 18:42:12 +0000
In my message started on Thursday, 10 January 2002 12:29:25, I wrote:
>
"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
[...]
>
>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.
Here's a more efficient version of the script I posted:
set myFolder to choose folder
-- 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
set fileCount to (count nameList1)
set sortedList to {}
set theDigits to "0123456789"
set i to 1
repeat while i is not greater than fileCount
-- Get the first (or next) initial letter
set thisLetter to character 1 of (item i of nameList1)
-- Separate the high and low numbers for this letter
-- and add them to the final list
set hiList to {}
repeat while i is not greater than fileCount and character 1 of (item
i of nameList1) is thisLetter
set thisName to item i of nameList1
if thisName's length is greater than 2 and thisName's character 3
is in theDigits then
set end of hiList to thisName
else
set end of sortedList to thisName
end if
set i to i + 1
end repeat
set sortedList to sortedList & hiList
end repeat
sortedList
-- A list of file names, sorted as required
NG