Created
September 11, 2013 11:13
-
-
Save sebnilsson/6522182 to your computer and use it in GitHub Desktop.
Unpacking a zip-package and moving sub-folder to parent, in Chocolatey
This file contains 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
$packageName = '{PACKAGE_NAME}' | |
$url = 'http://SITE.COM/FILE.ZIP' | |
$subFolderFilter = '*SUBFOLDER*' | |
try { | |
$rootDir = Join-Path "$env:systemdrive\" $packageName | |
if (Test-Path "$rootDir") { | |
Write-Host "Removing existing files, keeping config-files" | |
Remove-Item "$rootDir\*" -Recurse -force -exclude *.config | |
} | |
Install-ChocolateyZipPackage "$packageName" "$url" "$rootDir" | |
$subFolder = Join-Path $rootDir (Get-ChildItem $rootDir $subFolderFilter | ?{ $_.PSIsContainer }) | |
Write-Host "Moving items from subfolder" | |
Get-ChildItem $subFolder -Recurse | ?{$_.PSIsContainer } | Move-Item -Destination $rootDir | |
Get-ChildItem $subFolder | ?{$_.PSIsContainer -eq $false } | Move-Item -Destination $rootDir | |
Remove-Item "$subFolder" | |
Write-ChocolateySuccess "$packageName" | |
} catch { | |
Write-ChocolateyFailure "$packageName" "$($_.Exception.Message)" | |
throw | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment