Reputation: 441
Question rewriten, due to clarity issues and not being able to delete it.
I have script that creates folder tree based on 7 number code. Lets assume our number is YYYYYYY then my folder hierarchy would be something like (number shows "layer" of folder) (sorry for calling it layers, as I don't know proper terminology)
"Layers" 1-3, has no files ever. Files might be only in layer 5. Now I need to make script that would show in which projects (2 layer) has no files, only empty folders.
Upvotes: 0
Views: 1243
Reputation: 11254
Since I'm not sure if "empty folders" are folders without subdirectories or only folders without files, I posted another query possibility, that also regards subfolders in folders. This should return all empty directories:
dir \*\* | ? { $_.PsisContainer } | ? {$_.GetFiles().Count -eq 0 -and $_.GetDirectories().Count -eq 0}
GetFiles
checks for files in the directory, and GetDirectories
checks for subdirectories.
Upvotes: 0
Reputation: 73586
PowerShell 3+ has -Directory and -File parameters of Get-Child-Item.
$L1withEmptyL2subfolder = dir $startFolder\*\* -Directory |
Where { !(dir $_ -Recurse -File | select -first 1) }
Pipelining is used to stop processing if even one file exists without enumerating the entire structure.
Upvotes: 2