Skip to content

Instantly share code, notes, and snippets.

@oesolberg
Last active September 4, 2018 07:09
Show Gist options
  • Save oesolberg/796718cfd4348698d6b1e4f2e179b4d5 to your computer and use it in GitHub Desktop.
Save oesolberg/796718cfd4348698d6b1e4f2e179b4d5 to your computer and use it in GitHub Desktop.
changes to fix-output.ps1
Param(
[string]$configuration,
[string]$keep
)
if ($configuration -eq "") {
$configuration = "Debug"
}
if ($keep -eq "") {
[xml]$proj = get-content (gci $PSScriptRoot\* -Include *.csproj, *.vbproj | select -First 1 -ExpandProperty FullName)
$keep = $($proj.Project.PropertyGroup.AssemblyName[0])
}
$keep = $keep.Replace("HSPI_", "")
""
"*** Keeping $keep ***"
""
$source = "$PSScriptRoot\bin\$configuration"
$destination = "$source\bin\$keep"
if ((test-path $destination) -eq $False) {
mkdir $destination -Verbose
}
gci $source -File | where { $_.Name -notmatch ".*$keep.*" } | % {
Move-Item $_.FullName -Destination $destination -Force -Verbose
}
""
"*** Checking for subfolders with files that need to be added to output ***"
""
### Test for the following paths:
### HTML\Help\(appname)
### Html\(appname)
### Html\images\(appname)
### Html\includes\(appname)
### scripts\(appname)
### scripts\includes\(appname)
### data\(appname)
#1. Check if the folder exists
#2. Check if the folder contains files
#3. Copy files to destination folder
$folderCollection=@("HTML\Help\","Html\images\","Html\includes\","Html\","scripts\includes\","scripts\","data\");
ForEach($folder in $folderCollection)
{
#Sett correct foldername
$sourceFolder=[io.path]::combine($PSScriptRoot,$folder,$keep);
#Check if we have any files in the folder
if ((test-path $sourceFolder) -eq $True)
{
$numberOfFoundFiles=( Get-ChildItem $sourceFolder | Measure-Object ).Count;
if($numberOfFoundFiles -gt 0)
{
#We found some files, now try to move them to the correct location
"Copying files from $sourceFolder"
$destinationFolder=[io.path]::combine($source,$folder,$keep)
if ((test-path $destinationFolder) -eq $False)
{
mkdir $destinationFolder -Verbose
}
#Move the files
Get-ChildItem -Path $sourceFolder | ForEach-Object -Process {
Copy-Item $_.FullName -Destination $destinationFolder -Recurse -Force -Verbose
}
}
}
else{
"Could not find folder $sourceFolder"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment