Excluding a Directory in 7Zip

 


When creating a script to streamline the creation of backup files of the ReactOS source code, I wanted a way to do so with just a single script. Naturally, I used a bash script, and decided on using the 7Zip file format as my personal choice. It provides good compression for what I want, and since I’m only interested in the contents of the files themselves, I have no reason to preserve the permissions of the files. But there was a problem.

When I tried to compress the entire directory, it was much bigger than I had anticipated. After quick review, I found that the directory was a GIT repository, and naturally had a .git folder included. Since the contents of that folder kept changing from each update, and was pretty big in size, I had no need for the folder. I could have made it to include every folder individually except for the .git folder, but that would have been too tedious. Plus, if the structure had changed, as it has a few times in the past, I would have had to go back and make changes, which I was not interested in doing.

It wasn’t until I learned about a certain command line option for 7zip that I learned how to exclude a certain folder while creating an archive. The switch in question is called -xr!.git. This switch is designed to exclude any directory with the name .git and include anything else. It keeps the script simple, and easy to manage. I hope this can help you in the future.

For access to the full script that I am referring to, click here.

Comments