The goal is to delete all files in a specified folder where the modification date is greater than X days.
My workflow: PDF proofs uploaded to a shared volume/folder - the sales staff has access to this volume so that they may pull proofs - after x number of days I want to delete any file that has been in there for over 14 days - its a maintenace/drive capacity issue
I searched the site and found the following:
http://macscripter.net/viewtopic.php?id=24957
what I don’t have is the actual delete portion of the script (i am sure its simple…but )
i understand that the portion of the script (below) says find those files whose modified dates are older than 14 days - but the script needs to know what to do with the results? how do i define what to do with the results?
set theFolder to choose folder
set files2delete to paragraphs of (do shell script "find " & quoted form of POSIX path of theFolder & " -type f -mtime +14")
would i do “mv”? or “rm”
set posix_trashFolder to POSIX path of (path to trash)
do shell script??
My artists brain is not allowing me to make this into a cohesive script.
Hi,
the find command can process the found files with the -exec flag
set theFolder to choose folder
do shell script "/usr/bin/find " & quoted form of POSIX path of theFolder & " -type f -mtime +14 -print -exec /bin/rm {} \\;"
Just add “-delete”
set theFolder to choose folder
set files2delete to paragraphs of (do shell script "find " & quoted form of POSIX path of theFolder & " -type f -mtime +14 -delete")
Script Fight!! LOL
My guess is that you are both right (but, what the heck do I know ; )
Is one solution better than the other? why?
Based on past experience, I would wager that Stefan’s solution is probably better than mine…
I don’t think so. The -exec version is more versatile, because you can execute anything.
Both methods do the same thing, they will delete the files
I did notice that Stefans gave a “result” (path and files delted) in the result portion of the script window.
Both scripts were effective. Thank You!!
Stefan - you spoke about versatility. Can you be more specific? How? What could I excute (besides my frontal lobe).
Thank you both again. I am learning.
Rick
“exec” is a way to, in a single line, take the result of one command and send it on to another command. In this case, the find command gets its results and they are sent along to the rm command. In my post, you are just saying, OK now delete all those files you found, but in Stefan’s you could add parameters to the rm command to filter what you were deleting with all of the parameters available to the rm command.
By the way, I got my solution by just checking the “man” page for find. There’s a lot of good info in there if you are not aware of it. Launch Terminal and type “man” and a space and then whatever command you want info on. In this case “man find”.
Model: iMac Intel 10.5.5
Browser: Firefox 3.0.2
Operating System: Mac OS X (10.5)