Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
    }
}
share|improve this question
    
Could you post the script? Or at least the portion that is where the pause happens? –  EBGreen Jun 22 '11 at 19:18
add comment

2 Answers 2

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.

share|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
add comment

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.

share|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
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.