Get newest file??-Newbie

Ok, not much experience here, but think there should be some way to do this fairly easily? I dunno- tell me if I’m wrong.

I have a folder with 10 files, I need to move one file which is named similar to another file but need the newest of the two files and the names are different each time but if I was able to get a file that was last modified out of the 2 files I would be in good shape. Any ideas?? :shock:

This worked for me…

on run
	set theFolder to choose folder
	tell application "Finder"
		set theFiles to (get files of theFolder as alias list)
		set newestFile to ""
		set baseDate to 0

		repeat with theFile in theFiles
			set theModDate to (modification date of (info for theFile))
			set theFileName to (name of (info for theFile))
			
			if baseDate is 0 then --> Set the first file as the baseline
				set baseDate to theModDate
				set newestFile to theFileName
			else --> If file is newer, save name and date to record
				if (theModDate > baseDate) then
					set baseDate to theModDate
					set newestFile to theFileName
				end if
			end if
		end repeat
	end tell

	display dialog ("Newest File: " & newestFile)
end run

Cheers,
j