Finder find earliest modified files

Hi,

What’s the best way to find the 10 earliest modified files in a folder without unix?

Thanks,

Editted: in other words the 10 most unused files.

Thanks,

Hello.

I am not sure if it is the best, but it is a way.

set nl to {}
tell application "Finder"
	set ml to items 1 thru 10 of reverse of (sort every item of folder "StikiesExport" of folder "Desktop" of home by modification date)
	repeat with i from 1 to 10
		set end of nl to item i of ml as alias
	end repeat
end tell

Edited

When you sort by modification date, it showed the newest files first, (greatest first) so I had to go back and re-edit it into the original form.

Yeah, I was hoping you wouldn’t need to ‘sort’. It seems that that’s the only way.

Thanks McUsrII,

Hello.

Maybe you could set a finder window into list view, ordered by date, and grab the 10 last files, but I hardly see any gain in that. There are also " a doze of sort routines" out there, written and compiled by Nigel Garvey, if Finder’s isn’t fast enough for you. But then the scripting becomes a little bit more complicated.

Actually, Finder’s sort of modification date, is kind of scripter-efficient. :slight_smile: If you use the unix sort, and the ls command, you’ll end up with something slightly more complicated, that I think is heavily locale dependent.

Hi McUsrII,

I finally remembered that listing the sorted files in Script Editor takes a very long time because of the result window. I need to remember not to end my results with a big list of references.

After thinking about it, because I didn’t want the big list, I was thinking about somehow getting the 10th earliest modified file then I could get ‘every file whose modification date is less than or equal to’ the 10th mod date.

I tried the window method, but anyway you ask the Finder to get or select anything, It always does it by name.

Thanks a lot,

Hello.

:slight_smile: You specifically said finder, but here is a way that returns the 10 last filenames of a folder, expanded with a full path.

do shell script "cd ~/Desktop;a=$(pwd); b=$(ls -t1 |tail -10) ; for i in $b ; do echo $a/$i ;done"