# Remove all files from existing DITA Copy folder, if exist
#region Get-ChildItem -Path 'C:\temp\DITA Files' -Include *.* -File -Recurse | foreach { $_.Delete()}
If (Test-Path 'C:\temp\DITA Files'){
    Remove-Item -Recurse -Force 'C:\temp\DITA Files'
}
If (Test-Path 'C:\temp\DITA.Zip'){
    Remove-Item -Recurse -Force 'C:\temp\DITA.Zip'
}
#endregion

#region Create the main folder for all the DITA content
New-Item 'C:\temp\DITA Files' -ItemType Directory
#endregion

#region Copy the version.txt file
# Copy-Item -Path "C:\DITA\version.txt" -Destination "C:\temp\DITA Files\version.txt"
#endregion

#region Create respository folder in new directory
# New-Item 'C:\temp\DITA Files\repository' -ItemType Directory
#endregion

#region Copy the contents of the original 'scripts' folder to 'DITA - Copy'
Copy-Item -Path "C:\DITA\scripts\" -Recurse -Destination "C:\temp\DITA Files\scripts"
#endregion

#region Copy the contents of the original 'server' folder to 'DITA - Copy'
[string]$SourceDirectory = 'C:\DITA\server\resources'
[string]$DestinationDirectory = 'C:\temp\DITA Files\server\resources'
Copy-Item -Force -Recurse -Verbose $SourceDirectory -Destination $DestinationDirectory
#endregion

#region Copy the contents of the original server index.html file to 'DITA - Copy'
[string]$SourceDirectory = 'C:\DITA\server\index.html'
[string]$DestinationDirectory = 'C:\temp\DITA Files\server\index.html'
Copy-Item -Force -Recurse -Verbose $SourceDirectory -Destination $DestinationDirectory
#endregion

#region Create transforms folders
New-Item 'C:\temp\DITA Files\transforms\extracts' -ItemType Directory
New-Item 'C:\temp\DITA Files\transforms\out' -ItemType Directory
New-Item 'C:\temp\DITA Files\transforms\out\pdf-css' -ItemType Directory
New-Item 'C:\temp\DITA Files\transforms\temp' -ItemType Directory
#endregion

#region Copy USBWebserver folder
# [string]$SourceDirectory = 'C:\DITA\USBWebserver'
# [string]$DestinationDirectory = 'C:\temp\DITA Files\USBWebserver'
# Copy-Item -Force -Recurse -Verbose $SourceDirectory -Destination $DestinationDirectory
#endregion

#region Copy WKFS_oXygen_Files folder
[string]$SourceDirectory = 'C:\DITA\WKFS_oXygen_Files'
[string]$DestinationDirectory = 'C:\temp\DITA Files\WKFS_oXygen_Files'
Copy-Item -Force -Recurse -Verbose $SourceDirectory -Destination $DestinationDirectory
#endregion

#region Copy all files to the SharePoint repository
# Change the destination directory path to suit personal path
[string]$SourceDirectory = 'C:\temp\DITA Files\*'
[string]$DestinationDirectory = 'C:\Users\kelly.mankenberg\Wolters Kluwer\Technical Writing Team Site - InfoDev\DITA Files'
Copy-Item -Force -Recurse -Verbose $SourceDirectory -Destination $DestinationDirectory
#endregion

#region Update version.txt file
$file = "C:\temp\DITA Files\version.txt"
$content = Get-Date -Format "yyyyMMddHHmm"
New-Item $file -ItemType File -Value $content
#endregion

#region Create Zip File
$compress = @{
    Path = "C:\temp\DITA Files\*"
    CompressionLevel = "Fastest"
    DestinationPath = "C:\temp\DITA.Zip"
  }
  Compress-Archive @compress -Force
#endregion

#region Copy Zip file to distribution location
$SourceFile = "C:\temp\DITA.Zip"
$Destination = "\\zusscgrcprodwebhelp.file.core.windows.net\webhelp\dev\InfoDev\DITA_InstallationFiles"
Copy-Item $SourceFile -Destination $Destination -Force
#endregion

#region Copy version.txt to distribution location
$SourceTxtFile = "C:\temp\DITA Files\version.txt"
$Destination = "\\zusscgrcprodwebhelp.file.core.windows.net\webhelp\dev\InfoDev\DITA_InstallationFiles"
Copy-Item $SourceTxtFile -Destination $Destination -Force
#endregion