Last active
October 26, 2015 22:13
-
-
Save dustinchilson/3d473bb1ddd6785fb9f4 to your computer and use it in GitHub Desktop.
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
function Clean-Folder | |
{ | |
param( | |
[string]$rootfolder, | |
[string[]]$excluded | |
) | |
$rootfolder = resolve-path $rootfolder | |
Push-Location $rootFolder | |
if($excluded -notmatch "^\s*$") | |
{ | |
$excluded = Resolve-Path $excluded | |
} | |
$filesToDel = Get-ChildItem $rootFolder -Recurse | |
# Excluding files in the excluded folder | |
foreach($exclusion in $excluded) | |
{ | |
$filesToDel = $filesToDel |?{$_.fullname -notlike ("{0}\*" -f $exclusion)} | |
# Excluding parent folders of the excluded folder | |
while($exclusion -notmatch "^\s*$") | |
{ | |
$filesToDel = $filesToDel |?{$_.fullname -ne $exclusion} | |
$exclusion = Split-Path -parent $exclusion | |
} | |
} | |
$filesToDel | Remove-Item -Recurse -ErrorAction SilentlyContinue | |
Pop-Location | |
} | |
Clean-Folder -rootfolder .\_site | |
pretzel bake | |
Clean-Folder -rootfolder ..\dustinchilson.github.com -excluded .git | |
Copy-Item .\_site\* ..\dustinchilson.github.com -Recurse |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment