• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Counting & trashing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Counting & trashing


  • Subject: Re: Counting & trashing
  • From: Nigel Garvey <email@hidden>
  • Date: Wed, 14 Jul 2004 14:54:11 +0100

Nigel Smith wrote on Tue, 13 Jul 2004 14:04:35 +0100:

>Of course, you don't need to sort the entire list, you can just get the
>oldest few.

>tell application "Finder"
> set {l1, l2} to {name, modification date} of every item <linebreak>
> of (choose folder)
>end tell
>set oldestList to {}
>set lastOldest to date "Thursday, January 1, 1000 0:00:00"
>repeat while (count of l1) - (count of oldestList) > 15
> set tmp to item 1 of l2
> set oldestIndex to 1
> repeat with x from 2 to count of l2
> if item x of l2 < tmp and item x of l2 is greater than <linebreak>
> or equal to lastOldest then
> set tmp to item x of l2
> set oldestIndex to x
> end if
> end repeat
> set end of oldestList to item oldestIndex of l1
> set lastOldest to item oldestIndex of l2
>end repeat
>return oldestList

It's slightly unreliable on my machine. Here's a more solid version:

set theFolder to (choose folder)
tell application "Finder"
set {l1, l2} to {name, modification date} of every folder of theFolder
end tell
set oldestList to {}
set numItems to (count l1)
repeat numItems - 15 times
set tmp to item 1 of l2
set oldestIndex to 1
repeat with x from 2 to numItems
if item x of l2 < tmp then
set tmp to item x of l2
set oldestIndex to x
end if
end repeat
set end of oldestList to item oldestIndex of l1
set item oldestIndex of l2 to date "Friday, 31 December 9999 23:59:59"
end repeat

-- tell application "Finder" to delete (every folder of theFolder whose
name is in oldestList)
return oldestList


NG
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.


  • Prev by Date: Re: Counting & trashing
  • Next by Date: Re: Counting & trashing
  • Previous by thread: Re: Counting & trashing
  • Next by thread: Re: Counting & trashing
  • Index(es):
    • Date
    • Thread