Archiving files and folders, deleting empty folders in the process

Hi, i'm looking for a all-in-one solution for archiving old files and folders in my fileserver (macmini)

On the Macmini i'm sharing two drives; "Fileserver" and "Archive"

The fileserver has a lot of files on it (nicely sorted in many folders and subfolders)

And what i want to do is the following:


I'd like to create several folders on the Fileserver called "_Archive"

For example: Fileserver/A/Aardvark/Projects/_Archive/

And move old folders and files in that folder to archive them.


Now the tricky part:

I would like to run an app or script (on the macmini) to regularly check the entire drive 'fileserver' for all folders named "_archive" and MOVE (not copy) the contents of that folder to the other drive "Archive"

While keeping its original path (only the contents of the folder, not the folder itself).


If there are any empty folders in the _Archive folder they should be deleted in the process.

(including folders with only hidden files).

If possible: remove "_Archive" from the new path. In this example: Archive/A/Aardvark/Projects/


before:

fileserver/A/Aardvark/Projects/_Archive/000Job/file.txt

after:

archive/A/Aardvark/Projects/000Job/file.txt


This way i want keep the server nice and clean while maintaining an archive of old projects.

(i'll set the Archive share to 'read only' to prevent unintentional deletions)


I've tried to script it myself, but that didn't work out well.

I also tried several third-party apps but none of them worked to satisfaction.


Some problems i encountered:

-filtering to only process the contents of the found _Archive folders.

-creating folders on the Archive drive with the same path, and especially the merging with existing folders

-deletions of files that were NOT copied (yikes)


How would you approach this? with a third-party app (which?) or with automator/applescript?

It should run without user-intervention.


Bonuspoints of there is a way to automatically create a alias to the archived folder in the _Archive folder on the fileserver.

In this case:

fileserver/A/Aardvark/Projects/_Archive/archive.alias. -> archive/A/Aardvark/Projects/

or

fileserver/A/Aardvark/Projects/_Archive/000Job.alias -> archive/A/Aardvark/Projects/000Job/


Any help or suggestion is welcome!


PS. Yes, i do make backups of both drives.


Mac mini 2018 or later

Posted on Feb 4, 2022 1:17 AM

Reply

Similar questions

2 replies

Feb 12, 2022 6:13 PM in response to Andre-_-

Andre-_- wrote:

Now the tricky part:
I would like to run an app or script (on the macmini) to regularly check the entire drive 'fileserver' for all folders named "_archive" and MOVE (not copy) the contents of that folder to the other drive "Archive"
While keeping its original path (only the contents of the folder, not the folder itself).

FYI, I would be careful about "moving" items to a different drive or volume (highlighted the "drive" reference from your post). If the process is interrupted, then you may end up with a mess and lose items in the process. It is much safer to "copy" the items to the other drive or volume, then delete the items from the original location if the copy process did not produce any errors. If others can access those shared items, then you would want to make sure to disable access or lock those items so changes are not introduced during the "move" (or "copy" & deletion) process.


I may not be much help here even if I understood exactly what you are trying to accomplish. Unfortunately I am not clear on exactly what the original layout is and what you hope for the finished layout. It appears you are trying to do everything within a current subfolder of a project, then moving the newly created archive to another location? If so, why not just create the new archive at the new location and transfer the desired items to that new archive (or at least place the "_Archive" folder outside of the project)? This would greatly ease the logic of the script as the script won't have to exclude the "_Archive" sub folder itself when sorting through the project.


Also depending on your purpose of this archive, maybe you should consider putting the items into an archive file such as a .tgz or .dmg archive which can also allow those files to be compressed to save space.


Edit: added "if the copy process did not produce any errors" to the first paragraph of my reply regarding the copy process as this is very important to check for errors before removing the items from the original location.

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.

Archiving files and folders, deleting empty folders in the process

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