Wednesday, July 5, 2006
By: Matthew Doucette
WinRAR is a file compressor / archiver great for backing up data. Download WinRAR at rarlab.com/download.htm.
WinRAR Tip #3: Delete Multiple Files out of Multiple RAR Files:
Use one of these convenient batch files:
Windows version WinRAR batch file:
REM Windows Version
for %%I in (*.rar) do "C:\Program Files\WinRAR\WinRAR.exe" d -ibck -pYOURPASSWORD "%%I" *.exe *.txt *.rar
pause
Command line version WinRAR batch file:
REM Command Line Version
for %%I in (*.rar) do "C:\Program Files\WinRAR\RAR.exe" d -ibck -pYOURPASSWORD "%%I" *.exe *.txt *.rar
pause
They delete all *.exe, *.txt, and *.rar files out of every RAR file in the same folder as the batch file, including those password protected with "YOURPASSWORD" as the password. (Security tip: Do not use "YOURPASSWORD" as your password! Visit GRC's Ultra High Security Password Generator for tips on secure password generation.)
This batch file is only an example. You must modify it to specifically suit your needs.
To create the batch file, copy the above quoted text into Notepad and save it as "delete.bat", (without quotes). delete.bat will be your batch file. Put delete.bat in the same folder as the RAR files. (Always make backups before messing with your data. I recommend doing testing in a folder away from your actual data using copies of your actual data.)
Batch file warning: Double-clicking a batch file (.bat file) executes the batch file's commands, it does not open it for editing! To open a batch file, you must right-click it and choose "edit".
The example batch file above will delete all *.exe, *.txt, and *.rar files from all RAR files found in the current folder that are password protected via the password "YOURPASSWORD".
Let me break down the batch file for you
- REM stand for "remarks" and is how you provide commenting. Anything after "REM" is ignore during execution. In the examples above, I labeled the windows and command line versions using the REM command.
- for %%I in (*.rar) do is the batch file loop. It sets %%I to 'be' each RAR file in the current folder.
- "%%I", with one set of quotes, is the loop variable that 'becomes' each RAR file.
- "C:\Program Files\WinRAR\WinRAR.exe" d -ibck -pYOURPASSWORD "%%I" *.exe *.txt *.rar (from the Windows batch file version) is the full command that is run for each iteration of the loop, with "%%I" 'becoming' each RAR file in the current folder. This is similar for the command line version minus the path to the programs, explained next:
- "C:\Program Files\WinRAR\WinRAR.exe" is the full path to the Windows version of WinRAR. Change this if you have installed it in a different location.
- "C:\Program Files\WinRAR\RAR.exe" is the full path to the command line version of WinRAR. Change this if you have installed it in a different location.
- d is a WinRAR command line switch that signifies you wish to delete files from a RAR archive.
- -ibck is a WinRAR command line switch that signifies you wish WinRAR to run as a background process. This helps you continue to use your computer while WinRAR is working, as it makes WinRAR run under a low priority.
- -pYOURPASSWORD is a WinRAR command line switch that signifies the password you wish to use for archives that are password protected. Replace YOURPASSWORD with your actual password. If you do not use this command line switch and WinRAR runs into a password protected archive, it will ask you for it manually. This is only a problem if you have so many RAR files to process that you do not wish to wait to type in a password for each one.
- "%%I", already explained, is the loop variable that 'becomes' each RAR file.
- *.exe *.txt *.rar are the files you wish to delete. Here we have used wildcard specifications to indicate we want to delete all files that end in .exe, .txt, and .rar. The reason I used *.rar as an example is that I found that I had accidentally archived archives in some of my backups, so I had backed up a backup unnecessarily. I used this batch file technique to go in a clean them out.
Notice: Xona.com holds no responsibility for any data loss you experience. Make backups of your RAR files before you attempt to modify them, in case it does not work. Double check your work. If you have lots of RAR files, test the batch file on just a few of them (a few copies of them) first. Do not delete files you are not one hundred percent certain you do not need. Always make backups.
All WinRAR Tips:
- WinRAR Tip #1: Change Default Settings
- WinRAR Tip #2: Automatically Test Archived Files
- WinRAR Tip #3: Delete Multiple Files out of Multiple RAR Files
- WinRAR Tip #4: Run in Low Priority
- WinRAR Tip #5: Run with Multi-Threading
- WinRAR Tip #6: Make Additional WinRAR Copies Wait Their Turn
- WinRAR Tip #7: Batch File Backups
Have Any Tips To Add?
If you have WinRAR tips you would like to add, please contact us.
Also See:
External Links:
- RARLAB (the makers of WinRAR)
- WinRAR (Wikipedia)
- RAR (file format) (Wikipedia)
- Maximum Compression (shows maximum achievable compression ratio of 150+ compression programs )
- WinRAR (the company) (official publisher of RARLAB products, including WinRAR)
About the Author: I am Matthew Doucette of Xona Games, an award-winning indie game studio that I founded with my twin brother. We make intensified arcade-style retro games. Our business, our games, our technology, and we as competitive gamers have won prestigious awards and received worldwide press. Our business has won $190,000 in contests. Our games have ranked from #1 in Canada to #1 in Japan, have become #1 best sellers in multiple countries, have won game contests, and have held 3 of the top 5 rated spots in Japan of all Xbox LIVE indie games. Our game engines have been awarded for technical excellence. And we, the developers, have placed #1 in competitive gaming competitions -- relating to the games we make. Read about our story, our awards, our games, and view our blog.