Early in your ‘run’, you get the name and modification date of every file in the ‘moveTo’ folder:
tell application "Finder" to set d to {name, modification date} of files of alias "moveToFolder"
Then, as you process new files, you see if the name of a file is contained in item 1 of d. If it is, you shuffle through the name list to find out which one it is. Take its modification date (same value of the index) and put it in short sortable form like this:
to date_format(old_date)
set {year:y, month:m, day:d} to date old_date
tell (y * 10000 + m * 100 + d) as string to text 3 thru 4 & text 5 thru 6 & text 7 thru 8
end date_format
date_format("July 29, 2006") --> "060729" -- note that the argument is a date as text, not a date
-- If you want to pass it a date class, then remove 'date' from the first line
Append that to the name of the old one, and it will sort appropriately. You can save time by doing this to all your files; then you don’t have to worry about how to shuffle down a list changing 1 to 2, 2 to 3, etc. as newer ones are added. In my view, this is the best way to keep old versions. The current one has a recent date, all older are dated in an easy to read format and they Finder (and ASCII) sort in date order with the same text name, the newest last. If it is possible that a new one will be added on the same day as an earlier one, the handler above can be modified to include hours or hours and minutes to the date label, eg: 0607091542 as yymmddhhMM (year, month, day, hour, minute): July 9, 06 3:42 PM
See this thread too: http://bbs.applescript.net/viewtopic.php?id=18607. Nigel Garvey is the author of the handler above.
Date labeling also makes it easy to get one back from a script. You simply find the files whose name contains the textual part, and take the last of them.