中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-13 13:39
47,811 topics / 349,897 posts / today 0 new / 48,256 members
DOS学习入门 & 精彩文章 (教学室) » for call winrar batch generate compressed files everyone help take a look
Printable Version  3,293 / 23
Floor16 redtek Posted 2007-02-07 03:36
金牌会员 Posts 1,147 Credits 2,902
Brother, don't worry. I'm testing here (in case an error deletes your files, that would be a hassle:)), there's a shorter command that can do it, I'll post it later:))
Floor17 qingfushuan Posted 2007-02-07 03:41
高级用户 Posts 327 Credits 502
I tried:
for /f %%a in ('dir /b /s') do rar a /r /sfx %%a "%%a"

It seems to meet the requirements, but you need to put rar.exe and Default.SFX together, and it will be a self-extracting file directly.

Hope it helps you
Floor18 redtek Posted 2007-02-07 03:49
金牌会员 Posts 1,147 Credits 2,902
Reply to txtrain brother:

Before executing the following command (once and for all), you need to set initial values:

1) Set the path for the directory where Winrar.exe is located so that the system can find it.
  If you find it troublesome, you can copy WinRAr.exe to the Windows directory, which saves the trouble of manually setting the path :)


2) Copy the Default.SFX file in the \Program Files\WinRAR\ directory to the Windows directory.
  This is a "dictionary" file that Winrar or RAR needs to read when compressing a self-extracting file. If this file is not copied to the set path, it will not be found during compression, and thus cannot be compressed.

  After copying this file to the Windows directory, you can then complete the creation of the .exe self-extracting file in one compression command.



Type directly in the command line:






Compress the next-level directories and all files within them in the current directory into a self-extracting (.EXE) format, and store the compressed .exe file in the E:\BAK directory.

DIR /AD is to list only directories and filter out files.
If there is only dir /b, then both files and directory names will be enumerated by for.

I have added double quotes to the %i parameter and during operation, so that it can work normally when encountering directory names with spaces without errors.
If double quotes are not added, unexpected accidents may occur when encountering file names with spaces and encountering dangerous commands such as MD or RD...



I tested here :)
Version: RAR 3.0 unregistered version, Windows 2003

[ Last edited by redtek on 2007-2-6 at 02:52 PM ]
Floor19 redtek Posted 2007-02-07 03:51
金牌会员 Posts 1,147 Credits 2,902
Thanks a lot for the guidance from brother qingfushuan~:)
Floor20 qingfushuan Posted 2007-02-07 04:25
高级用户 Posts 327 Credits 502
I'm still a newbie. I came from Wuyou to the union just to learn about for. Thanks to the LZ for providing the interesting topic.

Actually, the LZ has already completed it, just consulting about rar /?. I don't dare to take credit. My shutdown script has: start c:\Progra~1\WinRAR\rar.exe a /r /s /m1 f:\mybackup\bak\%date%.rar f:\mybackup\backup This sentence, so I'm more familiar with it.

[ Last edited by qingfushuan on 2007-2-6 at 03:29 PM ]
Floor21 redtek Posted 2007-02-07 04:38
金牌会员 Posts 1,147 Credits 2,902
Brother qingfushuan, you're too kind. : )
In my eyes, there are no beginners. Everyone has countless things to learn. : ) ) )
Floor22 txtrain Posted 2007-02-07 06:23
初级用户 Posts 12 Credits 28
Just right, my last post is on the fifteenth floor, I didn't see it. There's also the second page, sorry. Thank you all for the time you spent on this problem for me. It's invaluable. But the imperfect place is that when this line "E:\temp>for /f %a in ('dir /b /ad') do winrar a /r /sfx /m5 "e:\temp\%a.exe" "%a"" is executed, N compressed files are opened for compression at the same time. Imagine that if N is large enough, the machine will definitely crash, and there may be compression errors because the machine is too busy compressing.

No more beating around the bush, this way it can be solved.
for /f %a in ('dir /b /ad') do start /w winrar /a /r /sfx /m5 "e:\temp\%a.exe" "%a"


Also, for sharing, I tell you some experience. Sometimes when compressing large files, there may be information like CRC failure. At this time, choosing the compression method "Best" and "Create solid compression" when compressing can generally solve the problem. If it still doesn't work, heh heh, try changing to a server version of the operating system. This is a little experience that I've been depressed about for a long time, and I take it out to save everyone from going the wrong way again.

There's another point to explain, why does that for statement have to follow another "%a" at the end?

[ Last edited by txtrain on 2007-2-6 at 05:43 PM ]
Floor23 redtek Posted 2007-02-07 07:15
金牌会员 Posts 1,147 Credits 2,902
With the experience talk about WinRAR from brother qingfushuan and brother txtrain, it will be much more convenient for netizens to refer to relevant contents in this post when solving some compression - related problems in the future ~ : )

【 Main text retrieval subject words: RAR WINRAR compression compressed file compressed directory Default.SFX /W /WAIT 】

[ Last edited by redtek on 2007-2-6 at 06:21 PM ]
Floor24 redtek Posted 2007-02-07 07:23
金牌会员 Posts 1,147 Credits 2,902
Originally posted by txtrain at 2007-2-6 17:23:
Sometimes when compressing large files, you may encounter messages like CRC failure. At this time, select the compression method "Best" when compressing. "Create solid compression" can generally solve the problem.



Appreciate the experience sharing from兄txtrain, learned it~:)
Collected~:)

[ Last edited by redtek on 2007-2-6 at 06:24 PM ]
Prev  1 2
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023