Last active
October 26, 2015 22:14
-
-
Save dustinchilson/3ceadef0ac1dba0041e8 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 -excluded .git | |
& .\tools\pretzel.exe bake |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment