console - Command line 7Zip to extract file by specified result path
2014-04
Is it possible to make 7Zip extract one file by name from archive to specified full path (including new filename)?
I've found only:
7zip e <archive> -o<resultDirectory> <filemask>
But it's not what I need.
You can use the -so
option to write the data to stdout
and redirect to your target file:
Example:
7z e -so xxxx.7z > yyy.txt
The commandline help of version 9.22
beta:
7-Zip [64] 9.22 beta Copyright (c) 1999-2011 Igor Pavlov 2011-04-18
Usage: 7z <command> [<switches>...] <archive_name> [<file_names>...]
[<@listfiles...>]
<Commands>
a: Add files to archive
b: Benchmark
d: Delete files from archive
e: Extract files from archive (without using directory names)
l: List contents of archive
t: Test integrity of archive
u: Update files to archive
x: eXtract files with full paths
<Switches>
-ai[r[-|0]]{@listfile|!wildcard}: Include archives
-ax[r[-|0]]{@listfile|!wildcard}: eXclude archives
-bd: Disable percentage indicator
-i[r[-|0]]{@listfile|!wildcard}: Include filenames
-m{Parameters}: set compression Method
-o{Directory}: set Output directory
-p{Password}: set Password
-r[-|0]: Recurse subdirectories
-scs{UTF-8 | WIN | DOS}: set charset for list files
-sfx[{name}]: Create SFX archive
-si[{name}]: read data from stdin
-slt: show technical information for l (List) command
-so: write data to stdout
-ssc[-]: set sensitive case mode
-ssw: compress shared files
-t{Type}: Set type of archive
-u[-][p#][q#][r#][x#][y#][z#][!newArchiveName]: Update options
-v{Size}[b|k|m|g]: Create volumes
-w[{path}]: assign Work directory. Empty path means a temporary directory
-x[r[-|0]]]{@listfile|!wildcard}: eXclude filenames
-y: assume Yes on all queries
More recent alpha versions (9.30) also do not allow to specify a target filename as direct parameter without redirection.
Any idea how to exclude a wild-carded path(s) from a command-line 7zip command?
I'm doing something this:
7z.exe a -t7z archive.7z FolderToArchive\ -mx0
and would like to exclude any \bin*.* or \obj*.* folders found underneath "FolderToArchive". To exclude files you can use the -x
parameter. The help file gives this example for using -x
:
7z a -tzip archive.zip *.txt -x!temp.*
That's great for excluding a file. But, again, I would like to exclude a wildcard-specified folder. Under my "FolderToArchive" there are multiple folders, under those folders there may or may not be "bin\" and "obj\" folders. I would like to not include these in the archive.
I've tried patterns like:
-x!bin* -x!bin*.* -x!\bin* -x!\bin*.* -x!\bin\* -x!\bin\*.*
None seem to exclude. Is this simply a limitation of 7zip?
To exclude the bin and obj folders recursively you can use the command:
7z.exe a -t7z archive.7z FolderToArchive\ -mx0 -xr!bin -xr!obj
To avoid bug, use -r or -xr carefully.
suppose you have directories like:
.\path1\path2\bin
.\path1\path2\src
.\path3\path4\path5\bin
.\path3\path4\path5\src
and run the command:
7z a -t7z archive.7z .\path1\path2 .\path3\path4\path5 -xr!bin
what you got in archive.7z: .\path2\src .\path5\src
That is, the path2 and path5 became the TOP folder in zip file. and both bin directories were excluded.
-x only support path/filename RELATIVE TO THE FINAL PATH IN ZIP FILE. So, if you only want to exclude
.\path1\path2\bin
but to include all the other 'bin' directories, the command should be like this:
7z a -t7z archive.7z .\path1\path2 .\path3\path4\path5 -x!path2\bin
I tried to use absolute path in -x, but never succeed.