Update list-empty-dirs.ps1

This commit is contained in:
Markus Fleschutz 2023-02-06 13:54:35 +01:00
parent e85b6e594b
commit b7f0bca5bb

View File

@ -1,10 +1,10 @@
<# <#
.SYNOPSIS .SYNOPSIS
Lists empty subfolders within a directory tree Lists empty subfolders
.DESCRIPTION .DESCRIPTION
This PowerShell script scans and lists all empty subfolders within the given directory tree. This PowerShell script scans and lists all empty subfolders within the given directory tree.
.PARAMETER DirTree .PARAMETER DirTree
Specifies the path to the directory tree Specifies the path to the directory tree (current working directory by default)
.EXAMPLE .EXAMPLE
PS> ./list-empty-dirs C:\ PS> ./list-empty-dirs C:\
.LINK .LINK
@ -16,16 +16,20 @@
param([string]$DirTree = "$PWD") param([string]$DirTree = "$PWD")
try { try {
$DirTree = resolve-path "$DirTree/" $StopWatch = [system.diagnostics.stopwatch]::startNew()
write-progress "Listing empty directories in $DirTree..."
$DirTree = Resolve-Path "$DirTree"
Write-Progress "Listing empty subfolders in $DirTree..."
[int]$Count = 0 [int]$Count = 0
Get-ChildItem "$DirTree" -attributes Directory -recurse | Where {$_.GetFileSystemInfos().Count -eq 0} | ForEach-Object { Get-ChildItem "$DirTree" -attributes Directory -recurse | Where {$_.GetFileSystemInfos().Count -eq 0} | ForEach-Object {
"📂 $($_.FullName)" "📂$($_.FullName)"
$Count++ $Count++
} }
"✔️ directory tree $DirTree has $Count empty directories"
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
"✔️ found $Count empty subfolders within directory tree $DirTree in $Elapsed sec."
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1 exit 1
} }