I have directories with hundreds of RAR files. Currently I use Powershell 2.0 with a script that utilizes WinRAR's RAR utility to decompress the files. The issue is that a small number of the files end up being encrypted, which pauses the script and requires interaction. Is there any way to do one of the following:

  1. Identify the encrypted files before trying to decompress
  2. Entirely ignore the encrypted files
  3. Automate an incorrect (or correct) password that will attempt to open the file, but just skip it if incorrect.

NOTE: Some of the compressed files encrypt just file contents, whereas others encrypt file name and file contents.

Relevent Code:

$files = Get-ChildItem
foreach($file in $files)
{
    if($file.Attributes -eq "Archive")
    {
        $folder = $file.basename
        rar x $file $folder\ -y
    }
}
link|improve this question

75% accept rate
Could you post the script? Or at least the portion that is where the pause happens? – EBGreen Jun 22 '11 at 19:18
feedback

2 Answers

up vote 3 down vote accepted
+50

Try the -p- parameter:

-p-     Do not query password

Edit: Just tested -p-, and extraction fails with a CRC error in the encrypted file file.ext. Corrupt file or wrong password.

link|improve this answer
Does just what I wanted. Fails password attempt and continues the script. Thanks. – viking Jun 29 '11 at 20:55
@viking: Please click the blue "+50" button next to the answer to award the bounty. – Wuffers Jul 3 '11 at 18:22
feedback

It's been a long time since I've used RAR for anything. I do recall that it had an extensive list of command line switches to use though. The 'av-' switch should disable the authenticity verification check, not sure what kind of output that will generate though. So the rar command would be something like:

rar x $file $folder\ -y av-

I'd suggest giving it a try and see what happens.

link|improve this answer
Thanks, I'll give it a try. – viking Jun 27 '11 at 12:48
No luck. Same behavior as before. – viking Jun 29 '11 at 19:59
feedback

Your Answer

 
or
required, but never shown

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