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.
Zypher
  • 37,405
  • 5
  • 53
  • 95
Lucas Kauffman
  • 16,880
  • 9
  • 58
  • 93

2 Answers2

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
}
Zypher
  • 37,405
  • 5
  • 53
  • 95
Steve
  • 51
  • 1
  • 1
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}
Scott Keck-Warren
  • 1,670
  • 1
  • 14
  • 23