Re: Finder: Delete files
Re: Finder: Delete files
- Subject: Re: Finder: Delete files
- From: Nigel Garvey <email@hidden>
- Date: Mon, 25 Jun 2001 14:24:09 +0100
Olivier Berquin wrote on Mon, 25 Jun 2001 09:37:59 +0200:
>
Hi all,
>
>
I would like to delete (in a folder) all the files that the date is not
>
"today". I've this, but it not work fine:
>
>
tell application "Finder"
>
delete (every file of folder (choose folder) whose ,
>
(modification date) < ((current date) - (1 * days))) -- 24 hours
>
-- empty trash
>
end tell
As Hugh's already mentioned, the Finder's 'whose' clause is bugged and
doesn't work reliably with numeric comparisons, such as dates. (Did I
hear this was fixed in 9.1?)
If you're likely to be deleting more files than you keep, the following
approach would save having to loop through every single modification date
in the folder:
tell (current date) to set {time, today} to {0, it}
tell application "Finder"
set fileList to sort files of (choose folder) by modification date
repeat with i from 1 to (count the result)
if the modification date of item i of fileList comes before today
then exit repeat
end repeat
delete items i through -1 of fileList
end tell
NG