Get list of nonempty directories

Posted on 2014-12-24
Last Modified: 2014-12-24
Suppose I have a directory tree like the following:

|-- Store1
|   |-- Clients
|   |-- Orders
|-- Store2
|   |-- Clients
|   |-- Orders
|-- Store3
|   |-- Clients
|   |-- Orders

From the home directory, I would like to run a Win or PowerShell script which gives me the list of all the Store1, Store2, Store3, ..., directories which have nonempty Orders subdirectory. What would such a script look like?

Thanks in advance.
Question by:Rothbard
LVL 23

Expert Comment

ID: 40516782
This would give you the directory names, including the files:
dir /b /a-d /s

Open in new window

Do you need just the directory names?

Author Comment

ID: 40516794
To clarify, I need a list of all the directories in the home directory which have a nonempty subdirectory called Orders.
LVL 23

Expert Comment

ID: 40516816
for /f "tokens=*" %a in ('dir /a-d /s') do @echo %a | find /i "Directory"

Open in new window

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.


Accepted Solution

Sean earned 450 total points
ID: 40516841
$a = Get-ChildItem "C:\Folder" -Filter Orders -Recurse
$a | Where-Object {$_.GetFiles().Count -ge 1} | Select-Object FullName

Author Comment

ID: 40516875
Thanks Zindel1. By the way, how is it possible to output the list to a file (as it is very long)?
LVL 18

Assisted Solution

by:Raheman M. Abdul
Raheman M. Abdul earned 50 total points
ID: 40516887
Adding to Zindel1,
you can output the result to a file by adding the following at the end of Zindel1's code
| out-file c:\temp\result.txt

Author Closing Comment

ID: 40516959

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup". After a while, you have entered a loop for Auto repair which does not fix anything and you will be in a  panic as all your work w…
This Micro Tutorial will give you basic overview of the control panel section on Windows 7. It will depth in Network and Internet, Hardware and Sound, etc. This will be demonstrated using Windows 7 operating system.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now