need help on comparing creation date of folders

hi everyone,
I am working on a handler which compares two folders and return the one with older creation date, but it doesn’t work as expected. Sometimes it return the right folder, sometimes it doesn’t.


on comparedate(folder1, folder2)
	set date1 to (creation date of (info for file folder1)) as string
	set date2 to (creation date of (info for file folder2)) as string
	if (date1 < date2) then
		return folder1
	else
		return folder2
	end if
end comparedate

I appreciate your help.

jin

First, if they’re folders, don’t try to coerce to files. Second, don’t coerce the date to a string, keep it as a date. You’re comparison will work if it is a date but if it is a string it won’t since it will compare the alphabetical order of the strings and that’s not what you want. This modified version will work for both files and folders:

Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]