2

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.

2 Answers 2

5

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
}
4

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}
5
  • The first one gives me: >> The second one gives me: pastebin.com/KX7ifaaZ Feb 2, 2012 at 16:29
  • What version of PowerShell are you using? Feb 2, 2012 at 20:32
  • Ehm The standard one in windows 7 :/ Feb 2, 2012 at 21:04
  • Try the first one again, I had an unterminated quote. Feb 3, 2012 at 15:56
  • 1
    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 Feb 3, 2012 at 16:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .