mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-12-24 23:59:17 +01:00
Update list-empty-dirs.ps1
This commit is contained in:
parent
e85b6e594b
commit
b7f0bca5bb
@ -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,14 +16,18 @@
|
|||||||
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])"
|
||||||
|
Loading…
Reference in New Issue
Block a user