Zip exclude subdirectory

I am trying to use the -x switch to exclude multiple subfolders from an archive that needs to be created every day. It works fine if I want to exclude folders directly below the root of the folder or drive being archived. However, if I want to exclude a folder that is more than one level deep from the root, it either gives an error or ignores the switch.

For example, I have four folders, Folder1, Folder2, etc. Inside each folder is subfolder1, subfolder2, etc. If I use 7za. If I use only -xr! I've tried this with both the -x! I've tried with relative path and absolute path. I've tried with trailing backslash and without. Nothing works. Am I doing something wrong, or is there just no way to exclude a sub-subdirectory from the archive?

It must work. Check that you use 7-zip 4. Try your test again and write log. I set up a special set of test folders and worked out the problem. It works best using relative pathnames. I think you could write "only" instead of "best" here. And that becomes a problem at the latest when you want to exclude directories on different drives. Maybe this feature can be added in a future version? I have 1. This is just a test. I have many files in main in the production server. I don't want to extract a2 files.

I'm getting crazy with this one Here my code.Join Stack Overflow to learn, share knowledge, and build your career. Connect and share knowledge within a single location that is structured and easy to search. It still just zips up the whole directory and everything it in.

I don't want dir1 dir2 file1 file2. The -x option is a bit strange; you list the files, starting with -xand ending with an sign:. For my particular system in order to exclude a directory I had to put quotes around my excluded directories and it worked like a charm:.

In my limited experience with the zip command, it seems like the -x option wants to pattern match the whole pathname of the file. So if you want to exclude everything in the dir1 dir2 directories and any file named file1 file2 then try something like this:.

The way you had it would only exclude files and directories that exactly matched those names at the root level. People who code: we want your input. Take the Survey. Stack Overflow for Teams β€” Collaborate and share knowledge with a private group. Create a free Team What is Teams? Learn more.

Zip command for excluding directories and files Ask Question. Asked 9 years, 4 months ago. Active 1 month ago. Viewed 13k times. I need to know the right -x syntax for the exclude functions to work. Improve this question. Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development.

zip exclude subdirectory

See What topics can I ask about here in the Help Center. Unix zip directory but excluded specific subdirectorieshow to exclude directories and file zipping a directory? Add a comment. Active Oldest Votes. The -x option is a bit strange; you list the files, starting with -xand ending with an sign: zip file. Example: mkdir tmp5 cd tmp5 touch a b c d e f g zip foo. Improve this answer. I got the backslashes from about.

Here's my actual command. Should only need the one -x at the head and the one at the end… and, are you really running zip from inside the directory that you're zipping? It's just more usual to be up a level, so that your ZIP contains a top-level folder.

Linux: Excluding directories when using zip

Not "wrong," just unusual. Looks good, and seems to work for me. Show 4 more comments. For my particular system in order to exclude a directory I had to put quotes around my excluded directories and it worked like a charm: zip -r myarchive. So if you want to exclude everything in the dir1 dir2 directories and any file named file1 file2 then try something like this: zip -r file.

zip exclude subdirectory

Tom Tom 1 1 1 bronze badge.Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.

zip exclude subdirectory

Connect and share knowledge within a single location that is structured and easy to search. Assuming your directory is a git repository and judging by the question, it very likely isyou can add directories that you want to exclude to the. Ubuntu Community Ask! People who code: we want your input. Take the Survey. Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams β€” Collaborate and share knowledge with a private group.

Subscribe to RSS

Create a free Team What is Teams? Learn more. Ask Question. Asked 7 years, 7 months ago. Active 1 year, 5 months ago. Viewed k times. I, need to zip a directory excluding some subdirectory and file; I used this: zip -r zipfile.

Zip Unzip Encrypt and Password Protecting files and Folder from different types Using Kali Linux

Improve this question. Braiam You want to exclude all subdirectories or only some of them? Add a comment.

Active Oldest Votes. I simply make a guess what you want. Improve this answer. Jakub Kukul Jakub Kukul 2 2 silver badges 6 6 bronze badges. Something like this should do the trick: zip -r zipped. Many thanks. Thank you.Super User is a question and answer site for computer enthusiasts and power users.

It only takes a minute to sign up. Connect and share knowledge within a single location that is structured and easy to search. I'm trying to zip a directory on Unix via SSH but I need to exclude a couple of subdirectories and all files and directories within them.

The subdirectory structure in the directories that I want to exclude is quite substantial so I can't simply add each directory to the -x argument. For my particular system in order to exclude a directory I had to put quotes around my excluded directories and it worked like a charm:. Just like other answers, but excluding directories entirely, instead of excluding all contents of directories:. In Ubuntu Server this commands works for zip a file excluding some folders, but with a little differences:.

I found this to work from David R Heffelfinger :. People who code: we want your input. Take the Survey. Sign up to join this community. The best answers are voted up and rise to the top.

Stack Overflow for Teams β€” Collaborate and share knowledge with a private group. Create a free Team What is Teams? Learn more. Unix zip directory but excluded specific subdirectories and everything within them Ask Question. Asked 9 years, 10 months ago. Active 7 months ago. Viewed k times. So far I have this: zip -r myarchive.

I also tried zip -r myarchive. Does anyone know how to do this? Improve this question. Gaff AlexanderMills - See this question. Add a comment. Active Oldest Votes. I was so close! The actual command I need is: zip -r myarchive. Improve this answer. This did not work for me on osx.

This worked for me zip -r theme. For my particular system in order to exclude a directory I had to put quotes around my excluded directories and it worked like a charm: zip -r myarchive. This is the one that works on Mac OS. As nobody has explained the reason for requiring either quoting the paths or escaping the asterisk, the reason is this: If the path is not quoted or the wildcard escaped, the shell will perform wildcard expansion before passing them to zipwhich will receive a list of paths to entries in the specified directories, but not paths to files within subdirectories of those, thus causing zip to not to ignore everything under the given directories.

Thank you for clearing things up zagrimsan. That both fixed the problem and explained the reason for it so that we understand it which will also come in handy in the future for other things. Relative paths works for me β€” Cazuma Nii Cavalcanti Jan 6 '20 at Gianluca P.I want to dump several folders into a single new zip file, but exclude some subfolders of the source folders. I don't necessarily have to keep the above variable structure.

I may have more source folders and exclusion folders later on. I just cannot figure out the syntax to make this work. I can get it to backup the source folders, but trying to exclude a single directory specified directly from the command line, or by specifying a list of exclusions using an exclusions file just does not work for me.

I could not find any documentation for how to format the exclusions file. Below, the first exclusion does not work, but the last 3 exclusions work. Also, using -xr instead of -x. I'd like to be able to specify specific folders and not wildcards if at all possible.

I may have figured this out. I think I could not specify the full paths as exclusions because it is looking for my exclusions within the source folders. Ultimately it was just easier to Robocopy what I needed minus the exclusions, then 7-zip it up and move the archive to the network.

The nature of my work causes me to work with local storage more than I would like, so my personal space on the network server is only used to backup my data. This makes my bad practice not as bad since I can schedule these backups. My script, if anyone wants to adapt it for their own usage. Not refined, still needs some cleanup, but gets the results I need. It was sort of adapted from a file server data migration script that I use, so it has some artifacts from that script in there. To continue this discussion, please ask a new question.

Get answers from your peers along with millions of IT pros who visit Spiceworks. Hello - I want to dump several folders into a single new zip file, but exclude some subfolders of the source folders.

Popular Topics in PowerShell.Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up. Connect and share knowledge within a single location that is structured and easy to search.

To exclude files, you can use the -x parameter. The help file gives this example for using -x :. That's great for excluding a file. But, again, I would like to exclude a wildcard-specified folder. I would like to not include these in the archive. That is, the. So, if you only want to exclude. According to Marco-spf is also available on Windows from 7-zip Based on zhazha's answer and make it more clear about how to exclude sub folders exactly.

On Windows 10, to backup a Visual Studio solution root folder:.

How to: Zip contents of a directory, excluding certain sub-directory

Works for the hidden huge. People who code: we want your input. Take the Survey. Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams β€” Collaborate and share knowledge with a private group. Create a free Team What is Teams? Learn more. Ask Question. Asked 11 years, 4 months ago. Active 1 year, 3 months ago.Join Stack Overflow to learn, share knowledge, and build your career.

Connect and share knowledge within a single location that is structured and easy to search. I'm attempting to create a zip file to serve as a backup of a directory, and eventually save that backup inside a "backups" folder in that directory. For illustration, "folder" includes "subFolder", "file1. The "backups" folder would contain various earlier backup files.

I want to create an archive of "folder" and all its contents, including subfolder, but exclude "backups". I realize there are problems with saving a zip file inside the folder being zipped, so I intended to save it somewhere else and then transfer it. But I don't know how to easily create an archive without the backups folder. My only thought is to write my own method recursively traversing the directory and excluding that one folder.

It seems like there must be a simpler way. Unfortunately, ZipFile does not offer a method that lets you filter entries. Fortunately, you can easily create a method like this based on this implementation :. In my opinion, you can take every file inside the folder excluding the "backups" folder and make an temporary folder with them to make the zip as you have said. Once you have this list, you can copy all this files, make the zip and erase the content.

I can not see a simpler way. In my case i needed to do this in PowerShell, here is the script I created based on the suggestions above:. People who code: we want your input. Take the Survey. Stack Overflow for Teams β€” Collaborate and share knowledge with a private group. Create a free Team What is Teams? Learn more. How to zip a directory's contents except one subdirectory? Ask Question.

Asked 5 years, 3 months ago. Active 2 months ago. Viewed 7k times. Here is what I originally wanted to use: ZipFile. CreateFromDirectory folderToZip, backupFileName ; I realize there are problems with saving a zip file inside the folder being zipped, so I intended to save it somewhere else and then transfer it. Any help would be greatly appreciated! Improve this question.

Add a comment. Active Oldest Votes. Fastest, true, Encoding. Improve this answer. Sergey Kalinichenko Sergey Kalinichenko k 71 71 gold badges silver badges bronze badges. I'd use Directory. EnumerateFiles and a foreach loop unless I'm sure that there will never be directories with lots of files in them. Haukinger I would do that too, but I decided to keep the implementation as close to the original, in order to illustrate how little needs to be changed in order to implement OP's requirements.

Thank you for the help!


thoughts on “Zip exclude subdirectory

Leave a Reply

Your email address will not be published. Required fields are marked *