Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to extract about 40 folders with each containing a rar, but I never have done in it powershell. In bash you can use */*.rar to extract them using a wildcard, but how do I this in powershell ? I tried something along

C:\Program Files (x86)\Unrar\UnRAR.exe' x  .\*\*.rar 

But it errors:

UNRAR 4.10 freeware      Copyright (c) 1993-2012 Alexander Roshal

Cannot read contents of .\*\*.rar
The filename, directory name, or volume label syntax is incorrect.
share|improve this question
add comment

2 Answers 2

Test this first because I don't have anything to test it on:

get-childitem -recurse -filter *.rar | %{"C:\Program Files (x86)\Unrar\UnRAR.exe" x $_.fullpath}

I'm not 100% sure if the x will cause it to extract to the current directory or the directory of the rar file so you may have to add a cd to the commands.

get-childitem -recurse -filter *.rar | %{cd $_.directory; "C:\Program Files (x86)\Unrar\UnRAR.exe" x $_.name}
share|improve this answer
    
The first one gives me: >> The second one gives me: pastebin.com/KX7ifaaZ –  Lucas Kauffman Feb 2 '12 at 16:29
    
What version of PowerShell are you using? –  Scott Warren Feb 2 '12 at 20:32
    
Ehm The standard one in windows 7 :/ –  Lucas Kauffman Feb 2 '12 at 21:04
    
Try the first one again, I had an unterminated quote. –  Scott Warren Feb 3 '12 at 15:56
    
Unexpected token 'x' in expression or statement. At line:1 char:84 + get-childitem -recurse -filter *.rar | %{"C:\Program Files (x86)\Unrar\UnRAR.exe" x <<<< $_.fullpath} + CategoryInfo : ParserError: (x:String) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : UnexpectedToken –  Lucas Kauffman Feb 3 '12 at 16:10
add comment

I use this:

$parent = 'c:\myrar_files'

$files = @()

Get-ChildItem $parent -Recurse -Filter "*.rar" | % {

    # Recurse through all subfolders looking for .rar files only.

    $files = $files + $_.FullName
}

foreach ($f in $files) {

    # UnRAR the files. -y responds Yes to any queries UnRAR may have.

   C:\scripts\WinRAR\unrar x -y $f
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.