[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
回复 15# idwma


    可以了, 还是会有空包, 但是空zip包不是0k 是1k

TOP

回复 16# 5i365
  1. @echo off
  2. for /f "delims=" %%i in ('dir /b /ad') do (
  3.     "C:\Program Files\7-Zip\7z.exe" a "%%i.7z" ".\%%i\*" -p123 -v1023m
  4.     for /f "tokens=3" %%j in ('dir /-c "%%i.7z.001"') do (
  5.         if %%j lss 200 (
  6.             del "%%i.7z.001"
  7.         ) else if %%j lss 1073741824 (
  8.             ren "%%i.7z.001" "%%i.7z"
  9.         )
  10.     )
  11. )
  12. pause
复制代码

TOP

回复 17# idwma


    是个办法, 好像实际大小是32k

TOP

回复 17# idwma


    好像不是for语句,用&都没有问题, 但是只要for语句, 并成一行, 不做处理一定有问题, 大侠能试试把这个搞成一行吗? 试了好多次, 无果

TOP

回复 19# 5i365
  1. cmd /c "@echo off&for /f "delims=" %%i in ('dir /b /ad') do ("C:\Program Files\7-Zip\7z.exe" a "%%i.7z" ".\%%i\*" -p123 -v1023m& for /f "tokens=3" %%j in ('dir /-c "%%i.7z.001"') do (if %%j lss 200 (del "%%i.7z.001") else if %%j lss 1073741824 (ren "%%i.7z.001" "%%i.7z")))"
复制代码

TOP

回复 20# idwma


    真是不错, 结果是对的, 但是在执行过程中, 有些错误的提示
--------------------------------------------------------------------------

C:\Users\Administrator\Desktop\A>cmd /c "@echo off&for /f "delims=" %i in ('dir /b /ad') do ("C:\Program Files\7-Zip\7z.
exe" a "%i.7z" ".\%i\*" -p123 -v1023m& for /f "tokens=3" %j in ('dir /-c "%i.7z.001"') do (if %j lss 200 (del "%i.7z.001
") else if %j lss 1073741824 (ren "%i.7z.001" "%i.7z")))"

7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21

Scanning the drive:
1 folder, 3 files, 20150760 bytes (20 MiB)

Creating archive: 1 中.7z

Add new data to archive: 1 folder, 3 files, 20150760 bytes (20 MiB)


Files read from disk: 3
Archive size: 20071613 bytes (20 MiB)
Everything is Ok
系统找不到指定的文件。

7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21

Scanning the drive:
0 files, 0 bytes

Creating archive: 101 日.7z

Add new data to archive: 0 files, 0 bytes


Files read from disk: 0
Archive size: 32 bytes (1 KiB)
Everything is Ok
找不到 C:\Users\Administrator\Desktop\A\101 日.7z.001

7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21

Scanning the drive:
0 files, 0 bytes

Creating archive: 102 本.7z

Add new data to archive: 0 files, 0 bytes


Files read from disk: 0
Archive size: 32 bytes (1 KiB)
Everything is Ok
找不到 C:\Users\Administrator\Desktop\A\102 本.7z.001

7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21

Scanning the drive:
1 folder, 3 files, 17433560 bytes (17 MiB)

Creating archive: 11 美.7z

Add new data to archive: 1 folder, 3 files, 17433560 bytes (17 MiB)


Files read from disk: 3
Archive size: 17247534 bytes (17 MiB)
Everything is Ok
系统找不到指定的文件。

7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21

Scanning the drive:
1 folder, 3 files, 17028438 bytes (17 MiB)

Creating archive: 12 国.7z

Add new data to archive: 1 folder, 3 files, 17028438 bytes (17 MiB)


Files read from disk: 3
Archive size: 16872190 bytes (17 MiB)
Everything is Ok
系统找不到指定的文件。

7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21

Scanning the drive:
1 folder, 3 files, 26099604 bytes (25 MiB)

Creating archive: 2 国.7z

Add new data to archive: 1 folder, 3 files, 26099604 bytes (25 MiB)


Files read from disk: 3
Archive size: 24190034 bytes (24 MiB)
Everything is Ok
系统找不到指定的文件。

7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21

Scanning the drive:
0 files, 0 bytes

Creating archive: 202 人.7z

Add new data to archive: 0 files, 0 bytes


Files read from disk: 0
Archive size: 32 bytes (1 KiB)
Everything is Ok
找不到 C:\Users\Administrator\Desktop\A\202 人.7z.001

7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21

Scanning the drive:
0 files, 0 bytes

Creating archive: 22 人.7z

Add new data to archive: 0 files, 0 bytes


Files read from disk: 0
Archive size: 32 bytes (1 KiB)
Everything is Ok
找不到 C:\Users\Administrator\Desktop\A\22 人.7z.001

C:\Users\Administrator\Desktop\A>pause
请按任意键继续. . .

TOP

本帖最后由 5i365 于 2022-1-3 19:00 编辑

回复 20# idwma

新开了一个贴, 期待很久了:
http://www.bathome.net/viewthread.php?tid=61208&extra=

TOP

回复 20# idwma


    看下面这个贴子的最后部分, 他说用cmd /c , 是不是说, 所有的多行批处理命令,中间用&合并后,然后在两边加上"号, 前面加上cmd /c 难道就可以了???
https://superuser.com/questions/ ... windows-commandline

TOP

回复 21# 5i365


    没有过滤第二个循环里dir的结果,这个错误提示不影响的
  1. dir /-c "%%i.7z.001"|findstr "%%i.7z.001"
复制代码
自动转单行这个不会呀

TOP

回复 20# idwma


   我把上面的改成下面 只处理批处理所在的 0号文件夹,里面文件打包后205M, 但是 把  lss 200 即使改为20 还是会被删除, 没有任何压缩包留下, 哪里出了问题?

cmd /c ""C:\Program Files\7-Zip\7z.exe" a "0号.7z" "0号\*" -p123 -v1023m & if "0号.7z.001" lss 200 (del "0号.7z.001") else if "0号.7z.001" lss 1073741824 (ren "0号.7z.001" "0号.7z")"

TOP

改成下面这样也不行:
cmd /c ""C:\Program Files\7-Zip\7z.exe" a "0号.7z" "0号\*" -p123 -v1023m & if "dir /-c "0号.7z.001"" lss 200 (del "0号.7z.001") else if "0号.7z.001" lss 1073741824 (ren "0号.7z.001" "0号.7z")"

TOP

回复 26# 5i365


    为什么要去掉for?

TOP

回复 27# idwma


    不想打包所有文件夹下的子文件夹了, 只打包 0号 文件夹

TOP

回复 28# 5i365


    里面那层截取大小的for还是要留的

TOP

回复 29# idwma


我尝试加上, 但是始终搞不定,

刚刚看了下面的文章,
https://www.jb51.net/article/49199.htm

找到了通过一行代码获取文件大小

for /f %%i in ('dir /b "0号.7z.001"') do echo %%~zi

TOP

返回列表