Hello all,
I'm attempting to script the finder into deleting every file beneath a folder that is older than a certain number of days old. Where I'm running into a problem is getting apple script to delete the files within the child folders as well.
I thought I got pretty close but when I use the "entire contents" container (which also deletes child files/folders) it wont allow me to specify age limit.
Here's what I got:
-- Set the age of files that you want to purge from your downloads folder
set modDate to (15)
-- Get current user's name
tell application "System Events"
set currentUser to (name of current user)
end tell
-- Check folder and move files to the trash that are older than N days.
tell application "Finder"
try
delete (entire contents in folder "tester" of folder "Desktop" of folder currentUser of folder "Users" of startup disk whose modification date is less than ((current date)) - modDate * days)
end try
end tell
tell application "Finder"
empty trash
end tell
I'm attempting to script the finder into deleting every file beneath a folder that is older than a certain number of days old. Where I'm running into a problem is getting apple script to delete the files within the child folders as well.
I thought I got pretty close but when I use the "entire contents" container (which also deletes child files/folders) it wont allow me to specify age limit.
Here's what I got:
-- Set the age of files that you want to purge from your downloads folder
set modDate to (15)
-- Get current user's name
tell application "System Events"
set currentUser to (name of current user)
end tell
-- Check folder and move files to the trash that are older than N days.
tell application "Finder"
try
delete (entire contents in folder "tester" of folder "Desktop" of folder currentUser of folder "Users" of startup disk whose modification date is less than ((current date)) - modDate * days)
end try
end tell
tell application "Finder"
empty trash
end tell