Extract multipart rar, deleting parts as they are extracted

IMPORTANT:

  • this script WILL delete the parts done extracting regardless of the end result, so if the process stops for a missing or corrupted part, you would not be able to start over

  • Open notepad and paste the following code and save it as _unrar.vbs in the same folder with your rar files.
  • Set UnRAR_Full_Path, First_Part and Target_Folder, make sure to keep the quotes.

The Script:

UnRAR_Full_Path = "c:\program files\winrar\unrar.exe"
First_Part = "YourArchiveName.part001.rar"
Target_Folder = "ExtractedFiles\"

mf_command = AddQuotes(UnRAR_Full_Path) & " x " & AddQuotes(First_Part) & " " & AddQuotes(Target_Folder)
mf_LZerosSplit = Split(First_Part, ".")
mf_LZerosPart = Mid(mf_LZerosSplit(UBound(mf_LZerosSplit)-1), 5)
If UBound(mf_LZerosSplit) > 3 Then
    WScript.Echo ("Too Lazy to deal with names the contains dots, only 2 are allowed. one before 'part' and one before 'rar'")
    WScript.Quit 1
End If
mf_LZ_UnderTen = ""
mf_LZ_UnderHundred = ""
mf_LZ_UnderThousand = ""

If Len(mf_LZerosPart) = 2 Then
    mf_LZ_UnderTen = "0"

ElseIf Len(mf_LZerosPart) = 3 Then
    mf_LZ_UnderTen = "00"
    mf_LZ_UnderHundred = "0"

ElseIf Len(mf_LZerosPart) = 4 Then
    mf_LZ_UnderTen = "000"
    mf_LZ_UnderHundred = "00"
    mf_LZ_UnderThousand = "0"
End If 
Set objShell = CreateObject("WScript.Shell")
Set objWshScriptExec = objShell.Exec(mf_command)
Set objStdOut = objWshScriptExec.StdOut

While Not objStdOut.AtEndOfStream
    strLine = objStdOut.ReadLine

    'WScript.Echo (strLine)

        If InStr(strLine,"Extracting from") Then
            mf_filename = Mid(strLine, 17)
            mf_partnameSplit = Split(mf_filename, ".")
            mf_partname = mf_partnameSplit(1)
            mf_partnumber = Mid(mf_partname , 5)
            If mf_partnumber > 1 Then
                mf_numtodel = mf_partnumber-1
                mf_LeadingZeros = ""
                If mf_numtodel < 10 Then
                    mf_LeadingZeros = mf_LZ_UnderTen
                ElseIf mf_numtodel < 100  Then
                    mf_LeadingZeros = mf_LZ_UnderHundred
                ElseIf mf_numtodel < 1000  Then
                    mf_LeadingZeros = mf_LZ_UnderThousand
                End If
                mf_filetodel = mf_partnameSplit(0) & ".part" & mf_LeadingZeros & mf_numtodel & ".rar"

                'WScript.Echo ("NOW DELETING: " & mf_filetodel)

                Set obj = CreateObject("Scripting.FileSystemObject")
                obj.DeleteFile(mf_filetodel)
            End If
        ElseIf InStr(strLine,"All OK") Then
            WScript.Echo ("looks like All Ok, Delete the Last part and Have a nice day :)")
        End If
Wend

Function AddQuotes(strInput)
    AddQuotes = Chr(34) & strInput & Chr(34)
End Function

Option one: Silent

run the _unrar.vbs file by double clicking it

Option two: Recommended

remove the ' from the start of

'WScript.Echo (strLine)

'WScript.Echo ("Deleting: " & mf_filetodel)

open cmd, direct to your folder and type "cscript _unrar.vbs"

  • using WScript.Echo without cscript will popup too many annoying message boxes

this script works by reading the Stdout of UnRAR.exe.

EDIT

Improved the script to automatically work with any name structure and with any number of parts up to 9999 parts. and to work with legacy archives that does not contain leading zeros.