Help With Apple Script Please

I use rsync to do backups of files. When doing the backups, any changed/deleted files are put in an archive folder that rsync creates and names (year_month_day) as follows:

2022_06_23

2022_07_14

2022_10_31


I’ve added an automatic purge of the archive folder with this script: find /Volumes/Backup/Archives -type d -mtime +30


This does work for archive folders that have many dated folders within them, but I’ve found that if the archive folder is empty, the above script may delete the archive folder itself.


I’ve tried adding a forward slash at the end: find /Volumes/Backup/Archives/ -type d -mtime +30


And I’ve tried adding a back slash at the end: find /Volumes/Backup/Archives\ -type d -mtime +30


But neither of those two will prevent the actual “Archives” folder from being sometimes deleted.


So the question. How dose one write the script so that the “find” script only looks at folders inside the “Archives” folder, and never the “Archives” folder itself?

Mac mini, macOS 12.6

Posted on Oct 31, 2022 12:42 PM

Reply
Question marked as Top-ranking reply

Posted on Oct 31, 2022 1:46 PM

Add to find "-mindepth 1" and possibly " -prune"

-mindepth n
             Always true; do not apply any tests or actions at levels less
             than n.  If any -mindepth primary is specified, it applies to the
             entire expression even if it would not normally be evaluated.
             “-mindepth 1” processes all but the command line arguments.

-prune       This primary always evaluates to true.  It causes find to not
             descend into the current file.  Note, the -prune primary has no
             effect if the -d option was specified.


4 replies
Question marked as Top-ranking reply

Oct 31, 2022 1:46 PM in response to MargeHomer

Add to find "-mindepth 1" and possibly " -prune"

-mindepth n
             Always true; do not apply any tests or actions at levels less
             than n.  If any -mindepth primary is specified, it applies to the
             entire expression even if it would not normally be evaluated.
             “-mindepth 1” processes all but the command line arguments.

-prune       This primary always evaluates to true.  It causes find to not
             descend into the current file.  Note, the -prune primary has no
             effect if the -d option was specified.


Oct 31, 2022 7:15 PM in response to MargeHomer

Tony T1, I'm still struggling with this. Taking my example script: find /Volumes/Backup/Archives -type d -mtime +30
What would it look like with the added "-mindepth 1"


This should work...

 find /Volumes/Backup/Archives -type d -mindepth 1 -mtime +30


...but you might have to use -prune as well


find /Volumes/Backup/Archives -type d -mindepth 1 -prune -mtime +30

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Help With Apple Script Please

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.