Reputation: 137
I am trying to extract a file using 7 zip and powershell command line. File is extracting with no issues but the 7zip throws error (Missing volume : sample.ZIP). I looks for zip file, still it extracts file. I want to suppress that error or I want to handle that error.
This is not a non terminating error. I also tried the below approach.
try {
$ExtractedFile = Get-ChildItem D:\test\ | % {& "C:\Program Files\7-Zip\7z" "e" D:\test\sample.z0004} -ErrorAction Stop
write-host "ExtractedFile(s): $ExtractedFile"
} catch {
Write-Host $error[0]
} finally {
Filename to be extracted: sample.z0004
I get the error:
Missing volume : sample.ZIP
Can anyone suggest how to overcome this issue?
Upvotes: 0
Views: 2436
Reputation: 13483
The problem is that a lot of metadata is stored in the root Zip file (sample.zip). You took 1 part of archive, which luckily for you contains entire files you need, but it could be otherwise for other archives and you will not be able to extract anything. So the error is totally valid. If you still want to suppress error, you can enclose your code with $ErrorActionPreference
and optionally add Out-Null
, like this:
$ErrorActionPreference= 'silentlycontinue'
$ExtractedFile = Get-ChildItem D:\test\ | % {& "C:\Program Files\7-Zip\7z" "e" D:\test\sample.z0004}
write-host "ExtractedFile(s): $ExtractedFile"
$ErrorActionPreference= 'Stop'
Upvotes: 1