China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-13 14:47
中国DOS联盟论坛 » DOS学习入门 & 精彩文章 (教学室) » for call winrar batch generate compressed files everyone help take a look View 3,296 Replies 23
Original Poster Posted 2007-02-06 23:02 ·  中国 北京 鹏博士BGP
初级用户
Credits 28
Posts 12
Joined 2007-01-19 05:33
19-year member
UID 76978
Gender Male
Status Offline
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 ]
Floor 2 Posted 2007-02-06 23:22 ·  中国 北京 东城区 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
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,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 3 Posted 2007-02-06 23:51 ·  中国 北京 鹏博士BGP
初级用户
Credits 28
Posts 12
Joined 2007-01-19 05:33
19-year member
UID 76978
Gender Male
Status Offline
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.
Floor 4 Posted 2007-02-07 00:00 ·  中国 北京 东城区 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
m<0..5> Set compression level (0=store...3=default...5=maximum)

rar a /r /m5 ..... The M5 parameter is maximum ratio compression:)
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 5 Posted 2007-02-07 00:06 ·  中国 北京 鹏博士BGP
初级用户
Credits 28
Posts 12
Joined 2007-01-19 05:33
19-year member
UID 76978
Gender Male
Status Offline
Then, what is the best compression method in WinRAR, 0 or 5? I can't figure it out.
Floor 6 Posted 2007-02-07 00:13 ·  中国 北京 东城区 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
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,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 7 Posted 2007-02-07 00:15 ·  中国 北京 鹏博士BGP
初级用户
Credits 28
Posts 12
Joined 2007-01-19 05:33
19-year member
UID 76978
Gender Male
Status Offline
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 ]
Floor 8 Posted 2007-02-07 00:23 ·  中国 北京 东城区 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
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,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 9 Posted 2007-02-07 00:29 ·  中国 北京 鹏博士BGP
初级用户
Credits 28
Posts 12
Joined 2007-01-19 05:33
19-year member
UID 76978
Gender Male
Status Offline
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 ]
Floor 10 Posted 2007-02-07 00:47 ·  中国 北京 东城区 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
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,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 11 Posted 2007-02-07 00:51 ·  中国 甘肃 兰州 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
I like 7z under the command line
Floor 12 Posted 2007-02-07 01:01 ·  中国 吉林 四平 联通
高级用户
★★★
Credits 859
Posts 413
Joined 2006-08-14 21:55
19-year member
UID 60532
Status Offline
I'll help you push it up. I also want to figure out your question.
Floor 13 Posted 2007-02-07 02:16 ·  中国 北京 鹏博士BGP
初级用户
Credits 28
Posts 12
Joined 2007-01-19 05:33
19-year member
UID 76978
Gender Male
Status Offline
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.
Floor 14 Posted 2007-02-07 02:33 ·  中国 北京 东城区 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
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 ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
txtrain +2 2007-02-07 02:52
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 15 Posted 2007-02-07 02:39 ·  中国 北京 鹏博士BGP
初级用户
Credits 28
Posts 12
Joined 2007-01-19 05:33
19-year member
UID 76978
Gender Male
Status Offline
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 ]
Forum Jump: