Re: Counting & trashing
Re: Counting & trashing
- Subject: Re: Counting & trashing
- From: John Stewart <email@hidden>
- Date: Wed, 14 Jul 2004 17:28:17 -0400
On 07/14/04 at +0100 Nigel Smith said this
>
property cutoff : 15
>
set targDate to ((current date) - (cutoff * days))
>
set targFolder to choose folder
>
>
tell application "Finder"
>
set foldersOfTargFolder to every folder of targFolder
>
if (count of foldersOfTargFolder) is greater than cutoff then
>
delete (every folder of targFolder whose creation date is less
>
than targDate)
>
end if
>
end tell
>
John,
>
>
That will only tend to work if you make 1 new folder every day -- no more,
>
no less -- and run the script daily. It may be what Bernard wants (he did
>
mention backups), but it isn't quite what he asked for in the first part of
>
his question.
>
>
But I agree you don't need any sorting. Either find the youngest 15 and
>
trash the rest, or keep trashing the oldest until you only have 15 left. I
>
guess the switch between the two methods would occur around the 30-item
>
mark, but I haven't done any testing.
>
>
Nigel
Nigel,
Might want to take another look at it :)
If there are less than 15 folders in the parent it won't delete any
regardless of age. It will delete all folders that are over 15 days old
no matter how many folders you make per day assuming there are more than
15 total in the parent folder. It doesn't care how many or how few you
make per day. It also doesn't care how often it's run.
I don't think I should have tied the cutoff date and the number of folders
but that came from the assumption of one folder a day in a backup folder.
It's easily changed.
There are only four steps and it really only needs two -
1. Determine the cutoff date
2. Count the folders in the parent
3. Test the count
4. Delete any folders older than cutoff date IF the count exceeds 15
A much simplier version which could easily be made into a folder action
script is -
property cutoff : 15
set targDate to ((current date) - (cutoff * days))
set targFolder to choose folder
tell application "Finder" to delete (every folder of targFolder whose
creation date is less than targDate)
JBS
-- You never really learn to swear until you learn to drive. (ain't
that the truth!) - George Carlin
_______________________________________________
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.