I had someone create a applescript for me that would delete files from a file server that were older than 45 days old. The only way he could create it was using the date modified but i need it to delete files by date added to the directory. Can you guys take a look at the script to see how it can be modified to date added.
–SET THE AGE OF FILES YOU WANT TO PURGE
set modDate to (45)
–SET TODAYS DATE
set todayDate to do shell script “date -n +%Y-%m-%d”
–SET ROOT FOLDER (WILL NOT DELETE ANYTHING IN ROOT FOLDER, ONLY ITEMS IN ITS SUBFOLDERS)
set rootFolderMac to “Edit Server Storage:ShoTransfer”
set rootFolderUnix to POSIX path of rootFolderMac
–SET TO BE DELETED FOLDER
set tbdFolderMac to rootFolderMac & “:.tbd”
set tbdFolderUnix to POSIX path of tbdFolderMac
–SET TODAY FOLDER
set todayFolderMac to tbdFolderMac & “:” & todayDate
set todayFolderUnix to POSIX path of todayFolderMac
–SET LIST OF FOLDERS AND COLOR LABELS TO IGNORE
set ignoreFoldersList to {“”}
set ignoreColorsList to {“”}
–0 = none, 1 = orange, 2 = red, 3 = yellow, 4 = blue, 5 = purple, 6 = green, 7 = grey
–SET LIST OF FOLDERS IN ROOT
tell application “Finder” to set mainFoldersList to every folder of folder rootFolderMac
–CREATE TODAY FOLDER IN TBD FOLDER
do shell script "mkdir -p " & the quoted form of todayFolderUnix
–START GOING THROUGH FOLDERS
repeat with currentFolder in mainFoldersList
try
tell the application “Finder”
–GET THE FOLDER NAME
set currentFolderName to the name of currentFolder as string
–GET THE FOLDER COLOR
set currentFolderColor to the label index of currentFolder as text
end tell
–IGNORE ALL FOLDERS LISTED IN IGNORE FOLDER LIST ABOVE
if ignoreFoldersList does not contain currentFolderName then
–IGNORE ALL COLORS LISTED IN IGNORE COLOR LIST ABOVE
if ignoreColorsList does not contain currentFolderColor then
–SET LIST OF CONTENTS IN CURRENT FOLDER
tell application “Finder” to set subContentsList to entire contents of currentFolder
–START GOING THROUGH CONTENTS IN CURRENT FOLDER
repeat with currentItem in subContentsList
try
tell the application "Finder"
if exists currentItem then
--GET THE ITEM NAME
set currentItemName to the name of currentItem as string
--GET THE ITEM COLOR
set currentItemColor to the label index of currentItem as text
--GET THE ITEM UNIX PATH
set currentItemUnix to POSIX path of (currentItem as alias)
--IGNORE ALL FOLDERS LISTED IN IGNORE FOLDER LIST ABOVE
if ignoreFoldersList does not contain currentItemName then
--IGNORE ALL COLORS LISTED IN IGNORE COLOR LIST ABOVE
if ignoreColorsList does not contain currentItemColor then
--GET THE ITEM MOD DATE
set currentItemModDate to modification date of currentItem
--CHECK IF THE ITEMS MOD DATE IS OLDER THAN PRESET NUMBER
if currentItemModDate is less than ((get current date) - modDate * days) then
--SET DYNAMIC TOP FOLDER FOR TBD/DATE FOLDER
set topFolderMac to todayFolderMac & ":" & currentFolderName
set topFolderUnix to POSIX path of topFolderMac
set destinationItemMac to topFolderMac & ":" & currentItemName
set destinationItemUnix to POSIX path of destinationItemMac
tell application "Finder"
if not (exists topFolderMac) then
do shell script "mkdir -p " & the quoted form of topFolderUnix
end if
do shell script "mv -f " & the quoted form of currentItemUnix & " " & the quoted form of destinationItemUnix password "f00tface" with administrator privileges
end tell
end if
end if
end if
end if
end tell
end try
end repeat
end if
end if
end try
end repeat
Model: mac mini i7 with promise storage
Browser: Safari 537.73.11
Operating System: Mac OS X (10.8)