[Batch] simple command-line rar

Source: Internet
Author: User
Tags decompress zip

This bat is for the virus full of the letter tube laboratory and specifically customized, in this computer room for two years, with the virus also played for two years, but also the face is not good enough, to go back and forth on the few viruses are not Autorun.inf is desktop__. INI is either the game.exe. vbs GOD HORSE

This room computer once poisoning rar can not be used, compression decompression can not be used

But inadvertently found that the command line version of the RAR is not affected, can still be strong can be used, then use bat to do a command-line version of RAR


¤ Feature 1: Automatically block computer room rogue virus files from all directories when compressing Desktop__.ini, this file is very rogue, as long as a USB stick

All the folders inside the U disk will appear this file, every time you come back to delete, and then the trouble did not want to tube

But this bat will automatically block the file when it is compressed, without compressing it into the package.


¤ Feature 2:5% recovery record will be added when compressing, in case the content of corrupted RAR can be recovered after RP

Computer room of the network is very slag B, often in my here to run a good file with the flying autumn sent to others will not be used, the intermediate transmission damaged

RAR is also, so RAR plus 5% recovery record is necessary to prevent open can also be repaired
= = Note = =
※ in my production test rar 3.90 version of the command line version of RAR can not decompress zip,7z and other formats of compressed package files

This problem is very strange, with the graphical interface of the WinRAR can, with the command line version of the RAR will not work, is not a kernel????

So files that are dragged and dropped into zip,7z are recognized as "other files" for compression when designed

And not to unzip, because also can not extract, prompt "not rar file". It is also possible that subsequent versions of the command-line RAR support this feature.


※ Also note that you cannot use the last. rar folder , because that will be judged to be compressed package files to unzip this folder

Obviously will be error, so you have to change the name and then compress this folder, this bat does not really perfect, such as this place should be used

File attributes to judge is D then the folder, no matter what name directly to compression, but with the attrib command to obtain the target property is difficult

Not to get hard, to get very simple, the key is not good to extract key attribute values from a string, you can't do it with findstr.

Then gave up, directly with whether the target has an extension to judge, all will have the end is. rar folder False, this is not the way

By doing this also learned a few other knowledge:

1,set < variable name > command only execution fails errorlevel changes to 1, success does not change to 0

2, in the program try not to give ERRORLEVEL manual assignment (such as: Set Errorlevel=n),

Otherwise, the ERRORLEVEL will not be able to instruct the command to return the result, errorlevel do not change manually, always set the value for the first time.

So the value of errorlevel is not the last resort to use the SET command to manually assign a value, division you do not want to use the ERRORLEVEL in the later code
3, you can use if "%%i" = "" to determine whether the variable is empty , did not pay attention to this problem, today only found that it can be used

Easy to use, just drag the files you want to manipulate.

will automatically determine whether to decompress or to compress, here drag and drop a folder under the C drive.

(PS: Do not support multi-file drag and drop, it should be said that CMD does not support)

Enter automatically determine the compressed file, after the compression is complete add 5% recovery record

Drag over a RAR file

Automatically determine the extracted files, decompression completed, no errors or warnings in the middle

If the target filename of the file to be unzipped exists, the target is not writable and the RAR hint does not unzip any files

BAT also prompts: "Note" The problem occurs during the operation, please carefully review the operation process prompt information

The main interface does not enter any information directly into the description document

Batch code, copy save to bat file to run:

@echo iftitle simple command-line rar by: Small Sea::Set Rar=%programfiles%\winrar\winrar.exeSetRar=%programfiles%\winrar\rar.EXESetfile=NULLif  not EXIST"%rar%"Echo"Error" You do not have WinRAR installed on your computer and cannot use this program &Echo.&EchoPress any key to exit ...&Pause>nul&Exit: TopCLSEcho******* simple command line rar***********EchoPlease drag and drop the file you want to operate here to enter (only support single file or folder)EchoIf viewing instructions, enterSetfile=help&Set/P file=if%file%==helpGoto Helpif  not EXIST%file%EchoThe file or folder you entered does not exist! Please re-enter &Pause>nul&GotoTop for/F "delims="%%i in ("%file:" =% "Do (set Exname=%%~xi:: Determine if there is an extension if"%%~xi" = = ""(set isexname=n) Else set Isexname=y):: If Y, there is an extension. Again if the extension is RAR, then unzip, otherwise compression:: If n, that is, no extension, it is identified as a folder or no extension file, to compress the file if%isexname%==y (if/i"%exname%" = = ". rar"(goto unrar) Else goto rar) ELSE goto rar::========= Compressed file ========:rarclsecho ^>^> compressed file for/f"Delims="%%i in ("%file:" =% ") Do("%rar%" A-r-ep1-rr5%%-xdesktop__.ini-x*\desktop__.ini "%%i.rar" "%%i")GotoCheck::======== extracting files ==========: UnrarCLSEcho^>^>Unzip the file for/F "delims="%%i in ("%file:" =% ") do (MD"%%~DPNI"1>nul 2>nul"%rar%" x "%%i" "%%~DPNI"):: ======= Check execution Results ========:checkif%errorlevel%==0 (echo.&echo "Congratulations" Operation completed successfully, press any key to return to the main menu ...&pause>nul& Goto top) Else (echo.&echo "Note" in the process of the problem, please carefully review the operation process prompt information Echo Press any key to return to the main menu ... Pause>nul&goto top):: ====== = Description Document ============:helpclsecho.echo┏━━━━━━━━━━━━━━━━━ Description ━━━━━━━━━━━━━━━━━━┓echo┃¤ This bat is for the virus-infested room, because once poisoning rar can not be used   , compression decompression is not used ┃echo┃ method, but found that the command line version of the RAR is not affected can still use, do this command line version rar┃echo┃¤ feature 1: In compression will automatically block the computer room rogue virus files from all directories Desktop__.ini┃echo┃                                  ¤ Feature 2: A 5% recovery record is added to the compression, in case the RP can recover the contents of the corrupted rar ┃echo┃== Note = = ┃echo┃※ in my production test rar 3.90 version of the command-line version of RAR can not decompress zip,7z and other formats ┃echo┃ compressed package files, so at design time if the drag and drop into the zip and other files will be compressed according to other files ┃echo┃ processing, and not Will go to unzip.               However, WinRAR is not affected, it is also possible that subsequent versions support this feature ┃echo┃※ note that the last is. rar folder, because that will be judged to be compressed package file and go to ┃echo┃ unzip this folder, obviously will error, so you have to rename the folder before compressing it ┃echo┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛echo.echo Press any key to return to the main menu ... pause>nul&goto topexit%errorlevel% 0 Successful%errorlevel% 1 failed set exname only execution failed ERRorlevel will be changed to 1, success will not change to 0 you can use if  "%%i" = "" to determine if the variable is empty
View Code

--Originally published in 2011-6-19 23:16

[Batch] simple command-line rar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.