|
txtrain
初级用户
 
积分 28
发帖 12
注册 2007-1-19
状态 离线
|
『楼 主』:
for 调用winrar批量生成压缩文件 大家帮忙看看
使用 LLM 解释/回答一下
目的是这样的:
我当前目录下有好多文件夹,里面分别放着不同的文件夹和文件,大小几M到几百M不等.我就想以当前目录为基准,进入目录,压缩,做成自解压包,删除压缩包,退出文件夹,如此这样徇环,直到把所有的文件夹都压缩完.其中关于调用winrar的环境变量以及相关的winrar参数(因为设置针对图形界面生效,所以必须调用winrar来完成)已经设置完毕,直接调用就可以了.我是这样写的:for /f %a in ('dir /b') do cd %a &winrar a -r x:\%a.rar&winrar s x:\%a.rar&del x:\%a.rar&cd ..就这样.但是在实际执行的过程中,第二个winrar命令不等第一个执行完就执行!因为工作量非常大,所以实在苦恼.请大家支个招.我已经反复实验过N遍了.用echo语句生成批处理肯定好使,但是我想更进一步,直接一条命令完事,高手指教.谢谢!
Last edited by txtrain on 2007-2-6 at 10:15 AM ]
The purpose is like this:
I have many folders in the current directory, and different folders and files are placed in them, with sizes ranging from a few megabytes to hundreds of megabytes. I just want to take the current directory as the benchmark, enter the directory, compress, make a self-extracting archive, delete the compressed archive, exit the folder, and so on in a loop until all folders are compressed. The environment variables for calling WinRAR and the relevant WinRAR parameters have been set (because it is set to take effect for the graphical interface, so it must be done by calling WinRAR), and it can be called directly. This is what I wrote: for /f %a in ('dir /b') do cd %a &winrar a -r x:\%a.rar&winrar s x:\%a.rar&del x:\%a.rar&cd.. That's it. But in the actual execution process, the second WinRAR command is executed before the first one is finished! Because the workload is very large, so I'm really troubled. Please give me some advice. I have repeatedly experimented many times. Using the echo statement to generate a batch file must work, but I want to go further and just have one command, expert advice. Thank you!
Last edited by txtrain on 2007-2-6 at 10:15 AM ]
|
|
2007-2-6 23:02 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
换成 WinRAR 目录下的 RAR.EXE 来加参数压缩(命令行界面)。
这样兄在执行压缩任务的时候 RAR.exe 是当前任务完成后,后面的命令才会执行,这样就可以正常进行先压缩再执行转换的工作了~:)
“其中关于调用winrar的环境变量以及相关的winrar参数(因为设置针对图形界面生效,所以必须调用winrar来完成)”,
把 rar.exe 文件拷贝到Windows目录内(因环境变量已含有Windows路径),这样就可以在任何地方直接调用 RAR.EXE 了:)
(这样可以省去手工添加 rar.exe 所在路径的设置)
Last edited by redtek on 2007-2-6 at 10:44 AM ]
Replace with RAR.EXE in the WinRAR directory for parameterized compression (command line interface).
In this way, when the brother executes the compression task, RAR.exe will complete the current task first, and then the subsequent commands will be executed, so that the work of compressing first and then converting can be carried out normally~:)
"Among them, about the environment variables for calling WinRAR and related WinRAR parameters (because the settings take effect for the graphical interface, so WinRAR must be called to complete)",
Copy the rar.exe file to the Windows directory (because the environment variable already contains the Windows path), so that RAR.EXE can be directly called anywhere~:)
(This can save the setting of manually adding the path where rar.exe is located)
Last edited by redtek on 2007-2-6 at 10:44 AM ]
|

Redtek,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2007-2-6 23:22 |
|
|
txtrain
初级用户
 
积分 28
发帖 12
注册 2007-1-19
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
以前试过用rar肯定没有问题,但是winrar有个参数叫"压缩方式":最好:我需要这一项,好像在rar没有找到这个参数哟
I tried using RAR before and it must have been fine, but WinRAR has a parameter called "Compression method": Best: I need this one, but it seems I can't find this parameter in RAR.
|
|
2007-2-6 23:51 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
m<0..5> 设置压缩等级 (0-存储...3-默认...5-最大)
rar a /r /m5 ..... M5参数是最大比率压缩:)
m<0..5> Set compression level (0=store...3=default...5=maximum)
rar a /r /m5 ..... The M5 parameter is maximum ratio compression:)
|

Redtek,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2007-2-7 00:00 |
|
|
txtrain
初级用户
 
积分 28
发帖 12
注册 2007-1-19
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
那么winrar里面的压缩方式最好是,0呢,还是5呢,想不明白
Then, what is the best compression method in WinRAR, 0 or 5? I can't figure it out.
|
|
2007-2-7 00:06 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
Winrar 加 /m5 参数是最大压缩比:)
分别用 winrar a /r /m5 ... 和 Winrar a /r /m0 ... 对比压缩同一目录,它们相差很多, 加/m5 参数的压缩比最大:)
Last edited by redtek on 2007-2-6 at 11:14 AM ]
Winrar with the /m5 parameter is the maximum compression ratio :)
Use winrar a /r /m5 ... and Winrar a /r /m0 ... respectively to compare compressing the same directory, they differ a lot, and the compression ratio with the /m5 parameter is the largest :)
Last edited by redtek on 2007-2-6 at 11:14 AM ]
|

Redtek,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2007-2-7 00:13 |
|
|
txtrain
初级用户
 
积分 28
发帖 12
注册 2007-1-19
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
也就是说0是压缩最好了?其实你用winrar直接设置就成了,还加什么参数?
我之所以一直想直接调winrar就因为直接设置好了.不用加参数
Last edited by txtrain on 2007-2-6 at 11:16 AM ]
That is to say, 0 is the best for compression? Actually, you can just set it directly with WinRAR, why add any parameters? The reason I've always wanted to adjust WinRAR directly is because I can set it directly. No need to add parameters
Last edited by txtrain on 2007-2-6 at 11:16 AM ]
|
|
2007-2-7 00:15 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
WinRAR (/M5 参数可以最大化压缩,把文件压缩到尽可能的最小:)
调用 WinRAR 确实不错~:)
不过我喜欢命令行,不太喜欢图形界面(主要是打字速度快,哈哈)
WinRAR (/M5 parameter can maximize compression and compress files to the smallest possible size:)
Calling WinRAR is really good~:)
But I like the command line, not so much the graphical interface (mainly because typing is fast, haha)
|

Redtek,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2007-2-7 00:23 |
|
|
txtrain
初级用户
 
积分 28
发帖 12
注册 2007-1-19
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
我要疯了,redtek你有没有环境自己试验一下
for /l %a in (1,1,9) do @echo %a >>%a.txt
for /l %a in (1,1,9) do mkdir %a
for /l %a in (1,1,9) do move %a.txt %a\
然后再给那几个目录里再拷点其它的文件夹和文件,压缩一下试试
for /f %a in ('dir /b') do cd %a&&rar a /r x:\%a.rar&&winrar s x:\%a.rar&&del x:\%a.rar&&cd ..
你自己看下是什么结果吧
一直忘记说了,我的测试环境是xp sp2
winrar版本:
RAR 3.50 beta 3 版权所有 (c) 1993-2005 Alexander Roshal 22 Apr 2005
注册给 - Internet -
Last edited by txtrain on 2007-2-6 at 11:37 AM ]
I'm going crazy, Redtek. Did you test it in your own environment?
for /l %a in (1,1,9) do @echo %a >>%a.txt
for /l %a in (1,1,9) do mkdir %a
for /l %a in (1,1,9) do move %a.txt %a\
Then copy some other folders and files into those directories and try compressing.
for /f %a in ('dir /b') do cd %a&&rar a /r x:\%a.rar&&winrar s x:\%a.rar&&del x:\%a.rar&&cd ..
You can see what the result is yourself.
I always forgot to mention that my test environment is XP SP2.
WinRAR version:
RAR 3.50 beta 3 Copyright (c) 1993-2005 Alexander Roshal 22 Apr 2005
Registered to - Internet -
Last edited by txtrain on 2007-2-6 at 11:37 AM ]
|
|
2007-2-7 00:29 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
压缩 NOTEPAD.EXE 记事本测试:
C:\WINDOWS>dir notepad.exe
驱动器 C 中的卷是 DISK-C
卷的序列号是 4089-CA39
C:\WINDOWS 的目录
2003-03-27 20:00 65,536 NOTEPAD.EXE
1 个文件 65,536 字节
0 个目录 3,117,764,608 可用字节
C:\WINDOWS>winrar a /m5 n1 notepad.exe
C:\WINDOWS>winrar a /m0 n2 notepad.exe
C:\WINDOWS>dir n?.rar
驱动器 C 中的卷是 DISK-C
卷的序列号是 4089-CA39
C:\WINDOWS 的目录
2007-02-06 11:48 34,459 n1.rar
2007-02-06 11:48 65,606 n2.rar
2 个文件 100,065 字节
0 个目录 3,117,658,112 可用字节
2007-02-06 11:48 34,459 n1.rar (这个是 /M5 压缩的,最好)
2007-02-06 11:48 65,606 n2.rar (这个是 /M0 压缩的)
WRAR 3.0 未注册版
系统:
名称: WindowsServer 2003, Enterprise Edition
版本: 5.2 内部版本 3790
Last edited by redtek on 2007-2-6 at 11:49 AM ]
Compression Test of NOTEPAD.EXE:
C:\WINDOWS>dir notepad.exe
Volume in drive C is DISK-C
Volume Serial Number is 4089-CA39
Directory of C:\WINDOWS
2003-03-27 20:00 65,536 NOTEPAD.EXE
1 File(s) 65,536 bytes
0 Dir(s) 3,117,764,608 bytes free
C:\WINDOWS>winrar a /m5 n1 notepad.exe
C:\WINDOWS>winrar a /m0 n2 notepad.exe
C:\WINDOWS>dir n?.rar
Volume in drive C is DISK-C
Volume Serial Number is 4089-CA39
Directory of C:\WINDOWS
2007-02-06 11:48 34,459 n1.rar
2007-02-06 11:48 65,606 n2.rar
2 File(s) 100,065 bytes
0 Dir(s) 3,117,658,112 bytes free
2007-02-06 11:48 34,459 n1.rar (This is compressed with /M5, which is the best)
2007-02-06 11:48 65,606 n2.rar (This is compressed with /M0)
WRAR 3.0 Unregistered Version
System:
Name: WindowsServer 2003, Enterprise Edition
Version: 5.2 Build 3790
Last edited by redtek on 2007-2-6 at 11:49 AM ]
|

Redtek,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2007-2-7 00:47 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
|
2007-2-7 00:51 |
|
|
anqing
高级用户
   
积分 859
发帖 413
注册 2006-8-14
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
帮你顶上去吧,我也想弄明白,你的问题?
I'll help you push it up. I also want to figure out your question.
|
|
2007-2-7 01:01 |
|
|
txtrain
初级用户
 
积分 28
发帖 12
注册 2007-1-19
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
我想我的问题确切的说是,连续调用两个外部命令,后一个不能等前一个执行完再执行
I think my problem is precisely that when I call two external commands consecutively, the latter one doesn't wait for the former to finish executing.
|
|
2007-2-7 02:16 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
Originally posted by txtrain at 2007-2-6 13:16:
我想我的问题确切的说是,连续调用两个外部命令,后一个不能等前一个执行完再执行
不好意思,刚才只注意探讨压缩比率了,忘了走题了:)
Start /w WinRAR.exe a /r ...... 压缩命令……
这样,只有 WinRAR 压缩任务运行完以后才会继续向下执行以下的命令:)
兄可将压缩的命令与转换 .rar 文件为自解压的命令分开两行写,不用 & 来连接它们为一行,这样 Start /w 参数就可以让它们执行完一个再执行一个,而不是并发方式的执行:)
即:
Start /w 第一个命令
Start /w 第二个命令
这样第一个命令执行完以后,第二个命令才会被执行:)
不会是我又看走题了吧? 上面是后一个命令等前一个命令执行完以后再执行:)
兄所说 “连续调用两个外部命令,后一个不能等前一个执行完再执行” ,后一个不等前一个命令执行完再执行就是说:并发运行对吧?
Start 第一个命令
Start 第二个命令
Last edited by redtek on 2007-2-6 at 01:38 PM ]
Originally posted by txtrain at 2007-2-6 13:16:
My question is exactly, when continuously calling two external commands, the latter one does not wait for the former one to finish executing before executing.
I'm sorry, just now I only focused on discussing the compression ratio and forgot to stay on topic : )
Start /w WinRAR.exe a /r ...... Compression command......
In this way, only after the WinRAR compression task is completed will it continue to execute the following commands downwards : )
Brother can write the compression command and the command to convert the .rar file to a self-extracting one in two separate lines, instead of connecting them as one line with &. In this way, the Start /w parameter can make them execute one after the other instead of executing concurrently : )
That is:
Start /w First command
Start /w Second command
In this way, the second command will not be executed until the first command is completed : )
Could it be that I'm off topic again? The above is that the latter command waits for the former command to finish executing before executing : )
Brother said that "continuously calling two external commands, the latter one does not wait for the former one to finish executing before executing", not waiting for the former one to finish executing means running concurrently, right?
Start First command
Start Second command
Last edited by redtek on 2007-2-6 at 01:38 PM ]
|

Redtek,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2007-2-7 02:33 |
|
|
txtrain
初级用户
 
积分 28
发帖 12
注册 2007-1-19
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
我可以很负责任的告诉你,试过了,不行
晕了,又试了一次行了,看来我的实际工夫还是做的不到位,谢谢了!!!
Last edited by txtrain on 2007-2-6 at 01:53 PM ]
I can tell you responsibly, tried it, didn't work
Dizzy, tried again and it worked, it seems my actual work is still not in place, thanks!!!
Last edited by txtrain on 2007-2-6 at 01:53 PM ]
|
|
2007-2-7 02:39 |
|
|