Dipanjan Das
Dipanjan Das

Reputation: 651

How to handle a CRC error while extracting a .zip through 7zip command in Powershell?

$sourceZip = "Path\Bla.zip\"
$destinationForExtraction = "Anotherpath\Bla"
7z x $sourceZip "-o$destinationForExtraction" *.exe -y

This code snippets gives an error 7z : ERROR: CRC Failed: SomeFile.exe. I have checked the crc of the above file. Yes the crc doesn't match. But the same zip gets extracted using manual procedure (Right Click > Extract To Folder).

Is there any way to handle this exception?

What's the reason behind these contradicting behaviors of 7z? It extracts properly while extracting manually but can not extract the same file while extracting through command line.

Upvotes: 2

Views: 3215

Answers (1)

Ranadip Dutta
Ranadip Dutta

Reputation: 9133

Redirecting the error should work for you:

$cmdOutput = 7z x $sourceZip "-o$destinationForExtraction" *.exe -y 2>&1

$cmdoutput should hold the value now.

Upvotes: 1

Related Questions