Last active
October 19, 2019 20:09
-
-
Save tylerapplebaum/6b5d8f4d91bf76435f087efe0546222e to your computer and use it in GitHub Desktop.
Identify directories with and without files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Get-SubdirectoryInfo { | |
[CmdletBinding()] | |
param( | |
[Parameter(HelpMessage="Specify the top level directory to search")] | |
[string]$TopLevelDir | |
) | |
#Find subdirectories with files | |
$Items = Get-ChildItem $TopLevelDir | Where-Object Attributes -ne Directory | Select-Object DirectoryName,Name,Length | |
#Find empty subdirectories | |
$Directories = Get-ChildItem $TopLevelDir | Where-Object Attributes -eq Directory | |
$EmptyDirs = New-Object System.Collections.Generic.List[Object] | |
ForEach ($Directory in $Directories) { | |
If ($Directory.EnumerateFiles().Exists -eq $null) { | |
$EmptyDirs.Add($Directory) | |
} | |
Else { | |
Write-Verbose "$Directory contains files" | |
} | |
} | |
} #End Get-SubdirectoryInfo | |
Function Remove-EmptySubdirectories { | |
#Remove empty directories - to do | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment