Skip to content

Instantly share code, notes, and snippets.

@dustinchilson
Last active October 26, 2015 22:14
Show Gist options
  • Save dustinchilson/3ceadef0ac1dba0041e8 to your computer and use it in GitHub Desktop.
Save dustinchilson/3ceadef0ac1dba0041e8 to your computer and use it in GitHub Desktop.
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