This one is a little more andvanced, as it “cleans up” after itself by deleting the .rar parent folder after successfully extracting it. Of course, use this at your own risk. It tends to be a little ruthless, considering there’s no going back as soon as the parent folder is deleted.

In other news: IT’S FRIDAY!

# # # # # # # # # # # # # # # # # # # #
#                                     #
# Unrar Shizzle v 2.0                 #
# www.fuffle.net                      #
#                                     #
# Unrar multiple arhives,             #
# through multiple subfolders         #
#                                     #
# Written by: Frank V                 #
# frank@fuffle.net                    #
#                                     #
# # # # # # # # # # # # # # # # # # # #

cls
$parent = "f:cachetemp"
$unrarred = "f:cacheunpacked"
$files = @()
$unrarpath = "C:Program FilesWinRARunrar.exe"

# Check unrar.exe default path.
if ((Test-Path -Path $unrarpath) -ne $true){
write-host "Unrar.exe not present in default unrar folder. Please verify"
break
}

# Recurse trough all folders, filter on .rar
Gci $parent -Recurse -Filter "*.rar" | % {
$files = $files + $_.FullName
}

# Start extract, using call parameter "&"
foreach ($f in $files) {
& "$unrarpath" x -y $f $unrarred

# In case of GREAT SUCCESS - delete rar parent folder
$folder = Split-Path -Path $f -Parent
if ($LASTEXITCODE -eq "0"){
Remove-item -Path $folder -Recurse
}
}

– F

2 thoughts on “Powershell Unrar script v2.0!”

  1. Thanks this is awesome, I just had problem when I installed unrar in the default Program Files (x86) folder because commandline doesn’t like spaces. I installed unrar in %systemroot% instead so I can use it from all directories. This script save me lot of time unpacking stuff, Cheers!

Leave a Reply