Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

List all folders only if there are no lower level folders or files

$
0
0

I have a simple query that lists all folders recursively that do not contain any files within them.  I also need to filter it so that it only lists folders that also do not have any sub-folders.   The following script will return only folders without files within them, but how would i also add it so that it lists folders without any sub-folders?  Thanks.

(Get-ChildItem C:\Temp -recurse | Where-Object {$_.PSIsContainer -eq $True}) `
| Where-Object {$_.GetFiles().Count -eq 0} | Select-Object FullName,Parent,Name,CreationTime,LastWriteTime


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>