Solved

Windows:  Unrar script

Posted on 2014-03-18
3
1,125 Views
Last Modified: 2014-03-19
Hi All,

I'm looking to do a bit of a tidy up on my media server.

I'm hoping someone can put together a script to unrar all my TV shows.

Around 50% of my shows are rar'ed in the following format;

D:\TV\Show Name\season n\show name s01e01\*.rar

I'd like them all to be extracted to the level below.

e.g.

D:\TV\Lost\season 1\Lost s01e01\Lost.s01e01.rar
D:\TV\Lost\season 1\Lost s01e01\Lost.s01e01.r00

would go to

D:\TV\Lost\season 1\Lost.s01e01.mkv



Could someone save me 2 days of unrar'ing by scripting it?



Many thanks

D
0
Comment
Question by:detox1978
  • 2
3 Comments
 
LVL 34

Accepted Solution

by:
Dan Craciun earned 500 total points
ID: 39939152
Don't know how to do this in batch, here's a Powershell solution:
# unrar archives to parent folder
# created for http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_28391754.html

$inputPath = "D:\TV"
$winRar = "C:\Program Files\WinRAR\WinRAR.exe"

gci $inputPath -Filter "*.rar" -Recurse | % {
    $parentFolder = $_.Directory.Parent.FullName
    Start-Process -FilePath $winRar -ArgumentList "e `"$($_.FullName)`" `"$parentFolder`"" -Wait
    #Remove-Item ($_.FullName.Substring(0,$_.FullName.Length-3) + "*") -Force
}

Open in new window


Replase $inputPath and $winRar to match your system's paths.

The script will look for any rar file in the $inputPath folder and unrar it in the parent folder (and wait until winrar finishes before moving on to the next archive).
Optionally, you can delete the archives by removing the # before Remove-Item

HTH,
Dan
0
 
LVL 2

Author Closing Comment

by:detox1978
ID: 39939947
Excellent thanks
0
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 39940000
Glad I could help!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question