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


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

TOP

回复 20# idwma


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

TOP

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

回复 20# idwma

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

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

回复 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

回复 17# idwma


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

TOP

回复 17# idwma


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

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

回复 15# idwma


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

TOP

回复 14# 5i365


    大意了if前面少了do加上去就好了

TOP

回复 13# idwma


    无法执行, 一闪就关了

TOP

回复 12# 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"') if %%j lss 1073741824 ren "%%i.7z.001" "%%i.7z"
  5. )
  6. pause
复制代码

TOP

本帖最后由 5i365 于 2022-1-2 19:35 编辑

回复 9# idwma


    现在有个现实的问题, 如果我设了 -1023m 分卷大小, 但是文件压缩后的大小没有超过1023, 压缩包的文件名还会是 abc.7z.001

如何加上条件判断, 包大小超1024m时, 才像上面名字似的分卷打包, 不超时压缩文件名就是abc.7z

另外, 当文件夹内为空时,也会打包成一个空包, 怎样也加个判断,空时不再打包? 感觉上面的判断有点困难, 因为怎样能获得压缩后的大小?

TOP

回复 10# 5i365

什么软件,如果只支持一条命还可以试试cmd /c "dir"的方式
循环放在一行的问题,举几个例子,不知道这样好不好理解
  1. for /f "delims=" %%i in ('dir /b /ad') do echo a
  2. echo b
  3. for /f "delims=" %%i in ('dir /b /ad') do echo a&echo b
  4. for /f "delims=" %%i in ('dir /b /ad') do (echo a)&echo b
  5. (for /f "delims=" %%i in ('dir /b /ad') do echo a)&echo b
复制代码

TOP

回复 9# idwma


    多谢, 问题1不好解决, 是个难题

TOP

返回列表