二一个

 找回密码
 立即注册
搜索
热搜: 交流 开发 分享
查看: 101|回复: 0

[Windows] 7zip把某个目录下的文件按文件夹分类极限压缩

[复制链接]
发表于 2017-9-27 14:42:46 | 显示全部楼层 |阅读模式
本帖最后由 yzy9952 于 2017-9-27 17:48 编辑

比如某个文件夹内,有a,b,c共3个文件夹,需要把这三个文件夹分别打成压缩包,忽略不在文件夹内的文件。把下面这行代码存成bat即可,不需要管理员权限。
-mx9 指的是极限压缩
a 添加文件

  1. for /d %%X in (*) do "c:\Program Files\7-Zip\7z.exe" -mx9 a "%%X.7z" "%%X"
复制代码


如图,文件夹内有aa,bb,cc共三个文件夹和一个txt文件。运行后会忽略txt文件,将三个文件夹分别压缩成三个压缩包。
1.png


另外,官方命令列表
Usage: 7za <command> [<switches>...] <archive_name> [<file_names>...]
[<@listfiles...>]

1. "a",添加文件
7z a -t7z files.7z *.txt

2. "d", 删除文件
7z d archive.zip *.bak -r
从zip文件中删除所有的*.bak文件

3. "e", 解压缩
7z e archive.zip

4. "l", 列出文件
7z l archive.zip

5. "t", 测试完整性
7z t archive.zip *.doc -r

6. "u", 更新
7z u archive.zip *.d

7. "x", 与e相同,但保留全路径

8. "m", 指定优化级别
Compression switch: -mx0
What it means: Don't compress at all.
Is called "copy mode."

Compression switch: -mx1
What it means: Very low compression.
It is called "fastest" mode.

Compression switch: -mx3
What it means: Fast compression mode.
Will set various parameters automatically.

Compression switch: -mx5
What it means: Same as above, but "normal."

Compression switch: -mx7
What it means: "maximum" compression.

Compression switch: -mx9
What it means: "ultra" compression.
(You probably want to use this.)

9. "-m"选项:
Switch: -mfb
Function: Specifies # of fast bytes.
Sometimes help with very "sparse" files.
Don't bother.

Switch: -mpass
Function: Number of passes for deflate compression.
Don't bother with this.
Automatically set with levels.

Switch: -md
Function: Specifies dictionary size.
Automatically set, so don't bother.

Switch: -mmt
Function: Enable multithreading.
Use if: you have quad-core and a really huge archive.
Specify "on" or "off".
This may be enabled by default; check the help file.

10. "-t"选项
指定压缩文件类型
Type switch: -t7z
Format: 7Z
Example filename: archive.7z (default option)

Type switch: -tgzip
Format: GZIP
Example filename: archive.gzip
archive.gz

Type switch: -tzip
Format: ZIP
Example filename: archive.zip (very compatible)

Type switch: -tbzip2
Format: BZIP2
Example filename: archive.bzip2

Type switch: -ttar
Format: TAR
Example filename: tarball.tar (UNIX and Linux)

Type switch: -tiso
Format: ISO
Example filename: image.iso

Type switch: -tudf
Format: UDF
Example filename: disk.udf

7z a -tiso archive.iso
7z a -tudf archive.udf

7z: executable name
a: add to archive
-tiso or -tudf: format of archive to create
archive.iso or archive.udf: name of archive to create

10. 硬压缩
Switch: -ms=on
Function: Enable solid mode.
This is the default so you won't often need this.

Switch: -ms=off
Function: Disable solid mode.
This is useful when you need to update individual files.
Will reduce compression ratios normally.

11. "-p"设定密码
7z a pw.7z *.txt -pSECRET

12. 其它选项:
Switch: -ssc
Function: Specify case-sensitive mode.
Useful for going between Linux and Windows.
Default: -ssc- on Windows (insensitive)
Default: -scc on Linux (sensitive)


Switch: -ssw
Function: Compress locked files.
Use if: you have problems with opening files.

Switch: -w
Function: Set working directory.
Use when you want to specify temp folders.

Switch: -aoa
Overwrite all destination files.

Switch: -aos
Skip over existing files without overwriting.
Use this for files where the earliest version is most important.

Switch: -aou
Avoid name collisions.
New files extracted will have a number appending to their names.
(You will have to deal with them later.)

Switch: -aot
Rename existing files.
This will not rename the new files, just the old ones already there.
Use when the new files are more important.

7z x test.zip -aoa

7z: use the 7-zip executable
x: use the extract command
test.zip: extract files from this archive

-aoa: overwrite all existing files. risky!

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|eryige.com ( 豫ICP备14029277-1 京公网安备 11010802022368号

GMT+8, 2017-11-24 15:14 , Processed in 0.024483 second(s), 29 queries .

Powered by Discuz! X3.4 & yzy9952

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表