Created
July 9, 2021 17:36
-
-
Save ChadDevOps/aab175a982a368b371d721c458e4698c to your computer and use it in GitHub Desktop.
Recursively extract all zip files into filename subdirectory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$folderPath=Get-Location; | |
$dash = '-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-' | |
Get-ChildItem $folderPath -recurse | %{ | |
if($_.Name -match "^*.`.zip$") | |
{ | |
write-host $dash | |
write-host '-+-+-+-+-+-+ EXTRACTING' | |
write-host $dash | |
$filenameandext = Split-Path $_.Name -leaf | |
$parent="$(Split-Path $_.FullName -Parent)"; | |
$parent = (New-Object -ComObject Scripting.FileSystemObject).GetFolder($parent).ShortPath | |
$fullPath = $parent + '\' + $filenameandext | |
$filename = [io.path]::GetFileNameWithoutExtension($_.FullName) | |
$outpath = $parent + '\' + $filename | |
$temp = New-Item -ItemType Directory -Force -Path $outpath | |
$OutShortPath = (New-Object -ComObject Scripting.FileSystemObject).GetFolder($outpath).ShortPath | |
write-host "From: $fullPath" | |
write-host "To: $OutShortPath" | |
$arguments=@("-aoa", "e", "`"$fullPath`"", "-o`"$OutShortPath`""); | |
$ex = start-process -FilePath "`"C:\Program Files\7-Zip\7z.exe`"" -ArgumentList $arguments -wait -PassThru -NoNewWindow; | |
if( $ex.ExitCode -eq 0) | |
{ | |
write-host "Extraction successful, deleting $fullPath" | |
rmdir -Path $fullPath -Force | |
} | |
write-host $dash | |
write-host | |
write-host | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment