1

I know variations of this question have been asked before. I've look at the answers and none of them work for me.

Running on Windows, using PowerShell.

// Arguments are on separated by newlines only for clarity in this question.
7z.exe u -r -up0q0r2x2y2z1w2 -ms=off -ssw -xr!dir1 -xr!dir1\ -xr!\dir1\* -xr!*\dir1 -xr!Dir3\Dir4\* -xr!Dir5\*IgnoredDirs  archive.7z Dir0\*

This is to say

-xr!dir1               // Various Syntaxes testing ignoreing dir1
-xr!dir1\
-xr!dir1\*
-xr!*\dir1 
-xr!Dir2\Dir3\*        // Ignore Dir3 only under Dir2
-xr!Dir5\*IgnoredDirs  // Ignore Dirs ending in IgnoredDirs only under Dir5

Not a single one of these seems to work.

I've also tried using the commands a or u.

Thanks in advance!

p.s. 7zip command line arguments are terrible.

2
  • 2
    I have no problem using CMD. For PowerShell, have you prefaced the command with an ampersand (&)?
    – harrymc
    Commented Apr 11, 2022 at 16:29
  • @harrymc Thanks for the tip about &. In this specific case a missing & wasn't the issue. I just misunderstood the way 7z's arguments work. Your tip did come in handy for a different thing I was working on.
    – DrFloyd5
    Commented Apr 12, 2022 at 18:00

1 Answer 1

1

Ok, I think I have this figured out.

using 7z u -xr!itemName archive.zip source\* Note: source\* will include the contents of source at the archive's root. source\ or source will include source in the archive's root.

itemName       // ignore all files or folders named itemName in source or a sub-Folder.
itemName\      // ignore all folders, but not files, named itemName in source or sub-folder.
itemName\*     // ignore all files in folders named itemName, but include the folder (it will be empty) in source or sub-folder.

If you want to ignore folders only in specific folders the syntax changes a little. You must prefix the itemName with *\

*\item1Name\item2Name\     // ignore all files and folders in folder item2Name in folders named item1Name
                           // i.e. ignore all files in folders in any path ending with the folder and sub-folder combination item1Name\item2Name
*\item1Name\*\item2Name\   // ignore all files in someFolder\item1Name\someFolder\item2Name
*\item1Name\**\item2Name\  // same as *\item1Name\*\item2Name\

Assuming the following dir / file layout. (Layout was generated with the tree command in the cmd.exe shell)

dir0
|   File 1-1.txt
|   File 1-2.txt
|   File Same Name In Multiple Folders.txt
|   
+---dir1
+---dir2
|   |   File 2-1.txt
|   |   File 2-2.txt
|   |   File Same Name In Multiple Folders.txt
|   |   
|   \---dir3
|           File 3-1.txt
|           File 3-2.txt
|           File Same Name In Multiple Folders.txt
|           
\---dir5
    |   File 5-1.txt
    |   File 5-2.txt
    |   File Same Name In Multiple Folders.txt
    |   
    +---dir6-IgnoreDirs
    |       File 6-1.txt
    |       File 6-2.txt
    |       File Same Name In Multiple Folders.txt
    |       
    \---dir7-IgnoreDirs
            File 7-1.txt
            File 7-2.txt
            File Same Name In Multiple Folders.txt
            

The answer to my question is

// File Contents of exclude
                       // below assumes using -xr
dir1\                  // Ignore any folder named dir1
*\Dir2\Dir3\           // Ignore Dir3 under any folder named Dir2
*\Dir5\*IgnoredDirs\   // Ignore Dirs ending in IgnoredDirs under any Dir5

// Command Line
7z u archive.zip dir0\* -xr@exclude
// Command Line for mirroring
7z u archive.zip dir0\* -up0q0r2x2y2z1w2 -ms=off -ssw -xr@exclude

Final fact, adding -r to the command line will act as if the excluded items are evaluated at every sub-folder level. Meaning 7z archive.zip dir0\* -r -xr!Dir1\ WILL be included because it's contents will be included because of the -r option.

Hope this helps you. -DF5

You must log in to answer this question.

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