Batch Extracting RAR packages recursively
December 15th, 2008 Posted in IT RelatedEver had a download consisting of multiple rarred parts? I guess you have. Nowadays everything is packed in winrar. Extracting something in winrar is very easy. Just right click -> extract here. but what if you have ALOT of RAR files? what if these RAR files are split? Then you need hours of waiting and clicking to keep everything nicely in its original folder.
I was tired of this one day. So i came up with the idea to write a script that will do it for me.
I wrote a VB script, which is controlling winrar.
The code:
Dim objFSO
Dim ofolder
Dim objStream
Dim folder
Set objFSO = CreateObject("scripting.filesystemobject")
folder = InputBox("Enter folder to unpack","UnRarer", "E:\Series\")
CheckFolder (objFSO.getfolder(folder))
MsgBox "File Search Completed."
Sub CheckFolder(objCurrentFolder)
Dim strTemp
Dim strSearch
Dim strOutput
Dim objNewFolder
Dim objFile
Dim objStream
strSearch = ".rar"
For Each objFile In objCurrentFolder.Files
strTemp = Right(objFile.Name, 4)
If UCase(strTemp) = UCase(strSearch) Then
'Got one
Dim rar
rar = objCurrentFolder.Path & "\" & objFile.Name
'MsgBox rar
Dim oShell
Set oShell = WScript.CreateObject ("WSCript.shell")
Return = oShell.run ("""F:\Program Files\WinRAR\unrar.exe"" e -o- """ & rar & """ """ & objCurrentFolder.Path & """", 1, true)
Set oShell = Nothing
End If
Next
'Recurse through all of the folders
For Each objNewFolder In objCurrentFolder.subFolders
CheckFolder objNewFolder
Next
End Sub
A small explantion of how it works: first we declare the objects which we will use and we ask what the folder is in which we will be looking for RAR files. Next we call the function which will search recursively for all RAR files. Basically the function looks for all files in the folder, and checks if their extension is .rar . If there is a RAR file found, a shell (windows CMD) will open and start a command that winrar understands. This command extracts the package. If the file already exists (when it was extracted before) the script will NOT overwrite the original file but just skip this package. When the extraction is finished, it will look for more rars. If there aren’t any, then it will check the subfolders for any RAR files.
This simple script will save you alot of time. You can copy the code in Notepad and save it as rarextractor.vbs or you can download it here.
please leave a comment if you found this post usefull