Skip to content

Instantly share code, notes, and snippets.

@NickJosevski
Created August 26, 2009 04:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save NickJosevski/175313 to your computer and use it in GitHub Desktop.
Save NickJosevski/175313 to your computer and use it in GitHub Desktop.
function Select-Folder($message='Select a folder', $path = 0) {
$object = New-Object -comObject Shell.Application
$folder = $object.BrowseForFolder(0, $message, 0, $path)
if ($folder -ne $null) {
$folder.self.Path
}
}
function Add-Zip
{
param([string]$zipfilename)
if(-not (test-path($zipfilename)))
{
set-content $zipfilename ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
(dir $zipfilename).IsReadOnly = $false
}
$shellApplication = new-object -com shell.application
$zipPackage = $shellApplication.NameSpace($zipfilename)
foreach($file in $input)
{
$zipPackage.CopyHere($file.FullName)
Start-sleep -milliseconds 500
}
}
$folder = Select-Folder 'Select the SketchFlow Package Folder...'
#could prompt user for deployment location also, for the final compressed file
$deploymentFolder = "$folder\..\Deployment"
$types = ".xap", ".html"
#PSisContainer - fetches only files not directories
#Group-Object - assists in the ForEach loop that performs the copy
$files= Get-ChildItem $folder | Where-Object {-not$_.PSisContainer} | Group-Object Extension
$files = $files | Where-Object {$types-contains$_.Name}
New-Item -itemType Directory -path $deploymentFolder -ea SilentlyContinue
$files | ForEach-Object { $_.Group | Copy-Item -destination $deploymentFolder }
#rename testpage to something even more obvious
Move-Item "$deploymentFolder\TestPage.html" "$deploymentFolder\LaunchMe.html"
Get-ChildItem $deploymentFolder -Recurse | Add-Zip "$folder\deploy.zip"
#moving the file because Add-Zip cannot take an adjusted path ($folder\..\file.zip) as input.
Move-Item "$folder\deploy.zip" "$folder\..\deploy.zip"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment