Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm (trying) to develop a program to operate the 7-zip console program (7z.exe) via ShellExecute() and passing it a computer-generated list of files.

Now what I want to do is this :

I want to pass it a command line telling it to include and exclude files : i.e

include these :
.... more files

exclude these :
.... more files

so I make a command line like this :

7z a -t7z -i!"...file to include" -x!"file to exclude" ... etc etc

I'm just repeating from memory so I know the command line might not be accurate

But what I enter doesn't work. I just get everything in path and path__. What I want is an archive that looks like this inside:

                        <everything in path\data\files\foo\bar except for foo.dat>
            <everything in path__\data\ except for slug.mp3>

Could I have some help on getting this result? Thanks

share|improve this question
In the first part of your question you want to exlude fish.dat and slug.mp3 and in the last part you say you want an archive with only these files. Which one is it? (If its a typo please correct the question by editing it. –  Rik Oct 12 '13 at 18:30

1 Answer 1

Without knowing your exact 7z-command it is just guessing but here it goes:

7z a -t7z -ir@"files_to_include.txt" -xr@"files_to_exclude.txt" ....

Note the r after -i and -x for recursive. You also probably used @ before the filename instead of the !. (or at least you should. ! is used for specifying wildcard at the command line :)

Then for your files_to_exclude.txt content. I believe you should use relative paths here. So don't specify the c:\.... before your paths. If your common paths in the include is c:\path\path2 you need to delete this from the exclude. The reason for this is that while 7z is compressing your files it already did away with the c:\path\path2-part (because not the entire path is stored, only the relative part). So your excludes don't match anymore. You can see this because when opening the .zip c:\path\path2 is not in the .zip. (So matching it does not work)

So your files_to_exclude.txt should look like this:

.... more files

So if after adding the r after -i and -x and changing the new files_to_exclude.txt you still have troubles we need to see your actual command.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.