摘自:http://t.zoukankan.com/meteoric_cry-p-4685445.html
在写很多工具的时候,可能会用到7z命令来进行压缩与解压操作。这里记录二个比较常用的操作:压缩、解压。
在dos窗口下输入7z命令,会显示7z的使用参数详情:
7-Zip 9.10 beta Copyright (c) 1999-2009 Igor Pavlov 2009-12-22
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
必选参数:最常用的命令有a(压缩)、x(解压),其它的命令诸如删除,解压出来不保留目录结构这种,一般情况下都用不到。
可选参数:最常用的就是-t{Type}
Type默认值为7z,还有其它的如:
Type | Format | Example filename |
-t7z | 7Z | archive.7z(默认) |
-tgzip | GZIP | archive.gzip,archive.gz |
-tzip | ZIP | archive.zip(兼容) |
-tbzip2 | BZIP2 | archive.bzip2 |
-ttar | TAR | tarball.tar(Unix/Linux) |
-tiso | ISO | image.iso(可能不支持) |
-tudf | UDF | disk.udf |
常用的就是-t{Type}以及-r、-o、-y
解压命令:7z x -tzip -y xx-13.zip (解压到当前目录,如需改变输出目录,需要附加使用-o)
压缩命令:7z a -tzip -r xx.zip a* b*
将目录a、目录b,压缩成一个xx.zip
更多参数的详情,可以参考这里:http://www.dotnetperls.com/7-zip-examples
在Windows的64位操作系统下,除需要7z.exe外,还需要7z.dll,我将他们打包为一个zip文件,否则你执行命令的时候可能会遇到上面的错误。你可以从这里直接下载>>
标签:解压,files,set,zip,压缩,archive,7z From: https://www.cnblogs.com/LiuYanYGZ/p/16859676.html