-
Notifications
You must be signed in to change notification settings - Fork 0
/
Delete.ps1
48 lines (39 loc) · 1.48 KB
/
Delete.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
# PowerShell script that recursively deletes all 'bin' and 'obj' (or any other specified) folders inside current folder
$CurrentPath = (Get-Location -PSProvider FileSystem).ProviderPath
# recursively get all folders matching given includes, except ignored folders
$FoldersToRemove = Get-ChildItem .\ -include bin,obj,build,node_modules,.next,.reports -Recurse | where {$_ -notmatch '_tools' -and $_ -notmatch '_build'} | foreach {$_.fullname}
# recursively get all folders matching given includes
$AllFolders = Get-ChildItem .\ -include bin,obj,build,node_modules,.next,.reports -Recurse | foreach {$_.fullname}
# subtract arrays to calculate ignored ones
$IgnoredFolders = $AllFolders | where {$FoldersToRemove -notcontains $_}
# remove folders and print to output
if($FoldersToRemove -ne $null)
{
Write-Host
foreach ($item in $FoldersToRemove)
{
remove-item $item -Force -Recurse;
Write-Host "Removed: ." -nonewline;
Write-Host $item.replace($CurrentPath, "");
}
}
# print ignored folders to output
if($IgnoredFolders -ne $null)
{
Write-Host
foreach ($item in $IgnoredFolders)
{
Write-Host "Ignored: ." -nonewline;
Write-Host $item.replace($CurrentPath, "");
}
Write-Host
Write-Host $IgnoredFolders.count "folders ignored" -foregroundcolor yellow
}
# print summary of the operation
Write-Host
if($FoldersToRemove -ne $null)
{
Write-Host $FoldersToRemove.count "folders removed" -foregroundcolor green
}
else { Write-Host "No folders to remove" -foregroundcolor green }
Write-Host