Should be simple

tell application "Finder"
	set thefile to the last file of folder "move to enlarged" --when sorted by date
	display dialog thefile
end tell

how can i get the name of the last file when sorted by date?

I don’t know how the sort order comes into play but this might get the name.

tell application "Finder"
	set thefile to the name of last file of folder "move to enlarged" --when sorted by date
	display dialog thefile
end tell

   tell application "Finder"
   set thefile to the name of last file of folder "move to enlarged" --when sorted by date
   display dialog thefile
end tell 

this code wont give it to me

any ideas
thx in advance i thought this would be simple but it has already been a long week

I am looking for the most recently dated file

   tell application "Finder"
   set thefile to the name of last file of folder "move to enlarged" --when sorted by date
   display dialog thefile
end tell 

this code wont give it to me it gives me the last alphabetical file

any ideas
thx in advance i thought this would be simple but it has already been a long week

ps sorry about the double post

i guess this is what i want but it won’t work

tell application "Finder"
	set thefile to the name of the last file of folder "tester folder" whose date modified is less than (current date) --when sorted by date
	display dialog thefile
end tell

A simple idea :
get the creation date and the name (at the same time) of every file of your folder
make a handler that will look for the oldest file, get the offset of the oldest date in your first, in the other list you will have the name of the file you’re lokking for :

set choosenFolder to (choose folder)
tell application"Finder"
set {dateList, nameList} to {name, creation date} of every file of choosenFolder
end

set myOffset to getOldestFile(dateList)
set file name to item myOffset of nameList --the oldest file

on getOldestFile(thisList)
– the code here
– Applescript wil answer true/false when making a comparaison betwenn two dates
end

i am a little confused about the handler

How can i make it give me the name of the oldeest file

but i guess that was my whole question to begin with :wink:

I also noticed that some files creation date are missing should i put an error handler in to use the date modified if Creation date is missing?

Here is some code that might help you, you’ll have to deal with missing date


tell application "Finder"
	set cf to choose folder
	set {NameList, DateList} to {name, creation date} of every file of cf
	set myOffset to my getOldestFile(DateList)
	display dialog item myOffset of NameList
end tell

on getOldestFile(DateList)
	set oldestDate to item 1 of DateList
	set offsetoldestDate to 1
	repeat with x from 1 to count DateList
		if (item x of DateList) > oldestDate then set {oldestDate, offsetoldestDate} to {(item x of DateList), x}
	end repeat
	return offsetoldestDate
end getOldestFile

Jean-Baptiste LE STANG to the rescue again

thx that will do the trick i had to play around with the fact that some files are missing a created date so i decided to use the modification date instead which is probably what i need anyway

thx again for your wonderful help