-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clean-folder.ps1
51 lines (43 loc) · 1.6 KB
/
clean-folder.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
param([switch]$VerboseSwitch = $false)
# $Verbose=$true -or $VerboseSwitch
$Verbose=$VerboseSwitch
# Write-Verbose "[$script] [$env:SnippetsInitialized] -not `$env:SnippetsInitialized: $(-not $env:SnippetsInitialized)" -Verbose:$Verbose
$script = $MyInvocation.MyCommand
if (-not $env:SnippetsInitialized) {
$fileInfo = New-Object System.IO.FileInfo (Get-Item $PSScriptRoot).FullName
$path = $fileInfo.Directory.FullName;
. $path/Snippets/_common.ps1;
Initialize-Snippets -Verbose:$Verbose
}
function Clean-Folder {
param(
[String[]]$P = @('obj', 'bin'),
[switch]$R = $false,
[switch]$F = $false,
[switch]$V = $false
)
Write-Verbose -Verbose:$V -Message "`$P: $P"
Write-Verbose -Verbose:$V -Message "`$R: $R"
Write-Verbose -Verbose:$V -Message "`$F: $F"
Write-Verbose -Verbose:$V -Message "`$V: $V"
#gci bin,obj -r
$items = Get-ChildItem $P -Recurse:$R -Verbose:$V -ErrorAction SilentlyContinue
if($items) {
Write-Verbose -Verbose:$V -Message "Removing ${items.length} items"
$items | Remove-Item -Recurse:$R -Force:$F -Verbose:$V -ErrorAction Stop
} else {
$itemsString=[System.String]::Join(',', $P)
Write-Verbose -Verbose:$V -Message "No items that match [$itemsString] were found to delete."
}
}
try {
$alias = set-alias -Verbose:$Verbose -Scope Global -Description "Snippets: [dev] Clean-Folder" -Name clean -Value Clean-Folder -PassThru
return "Execute ``Clean-Folder -r -f`` to remove ``bin`` and ``obj`` folders recursively."
}
catch {
Write-Host $Error
}
finally {
Write-Verbose "[$script] Leaving..." -Verbose:$Verbose
$Verbose = $VerboseSwitch
}