Re: Sorting file lists
Re: Sorting file lists
- Subject: Re: Sorting file lists
- From: kai <email@hidden>
- Date: Sun, 19 Oct 2003 22:50:38 +0100
on Sun, 19 Oct 2003 18:22:13 +0100, "Dr Digby L. James" wrote:
>
I'm creating a list of files using the list folder which I'm then
>
using to import files into Quark. Is there a simple way to list the
>
files according to date and time? The order I presently get is
>
alphabetical, so file-2.tiff comes after file-19.tiff. Or do I need
>
to first get the script to rename all of the files file-002.tiff, etc
>
so that the alphabetical order is the correct order?
Normally, you'd need to strip away the non-numeric characters, coerce the
remaining characters to numbers (1, 2, 3 - instead of "1", "2", "3") and
then sort your original list by their numerical equivalents. This is all
perfectly possible (if a bit long-winded) - and if you'd like to try it that
way, by all means come back.
However, I couldn't help noticing that - from your description at least -
your file naming protocol seems to be pretty consistent. If that's the case,
you might be able to use an alternative method that I've just been playing
around with. This is fairly fast, but relies on all the files in a folder
being named in exactly the same way (with the exception, of course, from the
core numbers - which shouldn't include any leading zeros).
If that all fits your situation, then you might try something like this:
--------------------------------------------------
to sortByLength(l)
set m to count l
set n to count l's first item
set r to {}
repeat until (count r) is m
set x to {}
set y to {}
repeat with i in l
if (count i) is n then
set x's end to i
else
set y's end to i
end if
end repeat
set r to r & x's contents
copy y's contents to l
set n to n + 1
end repeat
r
end sortByLength
set l to sortByLength(list folder (choose folder))
-- do something with the list 'l'
--------------------------------------------------
Like I said, if you need something more sophisticated, let us know...
---
kai
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.