Created
February 11, 2022 23:18
-
-
Save DoubleCouponDay/34cd463162460c5eb90f7500b8d1729f to your computer and use it in GitHub Desktop.
copy.ps1
This file contains hidden or 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
| $ErrorActionPreference = "stop" | |
| $backslash = "\" | |
| $inputdir = Read-Host -Prompt "Enter an absolute path to input folder: " | |
| $outputdir = Read-Host -Prompt "Enter an absolute path to the output folder: " | |
| $inputdirname = Split-Path -Path $inputdir -Leaf | |
| $old_copy = $outputdir + $backslash + $inputdirname + $backslash | |
| Write-Host "deleting previous deployment at $old_copy" | |
| Try | |
| { | |
| Remove-Item -Path $old_copy | |
| } | |
| Catch { | |
| Write-Host "Error deleting previous deployment." | |
| Write-Host "Could be bad name, bad paths or there was no previous deployment." | |
| } | |
| Write-Host "copying mirrored directory..." | |
| $mirrorfoldersitems = Get-ChildItem $inputdir | |
| function copyacrossallincludedscripts([string]$currentdirectory, [string]$currentdestination) | |
| { | |
| Write-Host $("traversing directory: " + $currentdirectory) | |
| $currentfiles = Get-ChildItem -Path $($currentdirectory + "\*") -File | |
| $currentsubdirs = Get-ChildItem -Path $currentdirectory -Directory -Exclude $excludes | |
| foreach ($item in $currentfiles) | |
| { | |
| Write-Host $("copying across file: " + $item.Name) | |
| Try | |
| { | |
| $currentdestinationexists = Get-Item -Path $currentdestination | |
| } | |
| Catch | |
| { | |
| $newdestinationcreated = New-Item -Path $currentdestination -ItemType 'directory' | |
| } | |
| $scripcopied = Copy-Item $item.FullName -Destination $currentdestination -Force | |
| } | |
| foreach ($subdir in $currentsubdirs) | |
| { | |
| copyacrossallincludedscripts -currentdirectory $subdir.FullName -currentdestination $($scriptdir + $subdir.Name) | |
| } | |
| } | |
| copyacrossallincludedscripts -currentdirectory $inputdir -currentdestination $old_copy | |
| Write-Host "deployment complete." | |
| Pause |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment