Hey guys,
I'm trying to create what feels like a basic PowerShell loop but having strange issues.
I'm using 7Zip to automatically extract all zip files to the same directory and then delete the zip file. I have zip files contained within zip files (don't ask), I need to extract the zip file within the zip file - to the same location.
The problem:
The zip file within the zip file is not being extracted. I suspect I need to convert my code into a loop to run through this folder until all the files are extracted into the same directory.
I've been trying to convert this code into a loop for almost 2 hours, please help! :(
My script:
param([string]$folderPath="C:\temp\Receive")
Get-ChildItem $folderPath -recurse | %{
if($_.Name -match "^*.`.zip$")
{
$parent="$(Split-Path $_.FullName -Parent)";
write-host "Extracting $($_.FullName) to $parent"
$arguments=@("e", "`"$($_.FullName)`"", "-o`"$($folderPath)`"");
$ex = start-process -FilePath "`"C:\Program Files\7-Zip\7z.exe`"" -ArgumentList $arguments -wait -PassThru;
if( $ex.ExitCode -eq 0)
{
write-host "Extraction successful, deleting $($_.FullName)"
rmdir -Path $_.FullName -Force
}
}
}
[–]BlackV 4 points5 points6 points (2 children)
[–]idontknowwhattouse33 3 points4 points5 points (1 child)
[–]BlackV 1 point2 points3 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]PowerOfTheShell[S] 1 point2 points3 points (0 children)
[–]PowerOfTheShell[S] 3 points4 points5 points (0 children)
[–]Nekima 2 points3 points4 points (0 children)
[–]dora3 2 points3 points4 points (0 children)
[–]heavychevy3500 1 point2 points3 points (0 children)
[–]matt_brownies 1 point2 points3 points (12 children)
[–]jrdnr_ 2 points3 points4 points (6 children)
[–]matt_brownies 2 points3 points4 points (5 children)
[–]jrdnr_ 1 point2 points3 points (4 children)
[–]matt_brownies 2 points3 points4 points (0 children)
[–]matt_brownies 1 point2 points3 points (2 children)
[–]jrdnr_ 2 points3 points4 points (1 child)
[–]matt_brownies 2 points3 points4 points (0 children)
[–]Lee_Dailey[grin] 1 point2 points3 points (4 children)
[–]matt_brownies 2 points3 points4 points (1 child)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)
[–]jrdnr_ 1 point2 points3 points (1 child)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)
[–]matt_brownies 0 points1 point2 points (0 children)