Skip to content

Instantly share code, notes, and snippets.

@brettinternet
Last active February 16, 2021 19:21
Show Gist options
  • Save brettinternet/d3b76b71cd8f852ca5ede19932c7a587 to your computer and use it in GitHub Desktop.
Save brettinternet/d3b76b71cd8f852ca5ede19932c7a587 to your computer and use it in GitHub Desktop.
PowerShell script to extract all ISO images in subfolders with 7zip - see improved batch script below
Get-ChildItem $folderPath -recurse | %{
if($_.Name -match "^*.`.iso$")
{
$parent="$(Split-Path $_.FullName -Parent)";
write-host "Extracting $($_.FullName) to $parent"
$arguments=@("x", "`"$($_.FullName)`"", "-o`"$($parent)`"");
$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
}
}
}
@brettinternet
Copy link
Author

brettinternet commented Jan 2, 2017

Recursively pull files out of directories to your current folder and optionally remove the directories.
Get-ChildItem $folderPath -Recurse -File | Move-Item
Get-ChildItem $folderPath -Recurse -Directory | Remove-Item

@brettinternet
Copy link
Author

brettinternet commented Apr 18, 2017

From StackOverflow

Simple batch script is an improvement

for /R "%~dp0" %%I in ("*.iso") do (
  "C:\Program Files\7-Zip\7z.exe" x -y -xr!"*.rar" -o"%%~dpI" "%%~fI" && del "%%~fI"
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment