8

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 :
c:\path\path2\path
c:\path\path2\path__\
.... more files

exclude these :
c:\path\path2\path\data\files\foo\bar\fish.dat
c:\path\path2\path__\data\slug.mp3
.... 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:

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

Could I have some help on getting this result? Thanks

1
  • 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, 2013 at 18:30

1 Answer 1

9

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:

path\data\files\foo\bar\fish.dat
path__\data\slug.mp3
.... 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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .