Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Get list of nonempty directories

Posted on 2014-12-24
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 25

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 25

Expert Comment

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

Open in new window

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

LVL 11

Accepted Solution

Sean earned 1800 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 19

Assisted Solution

by:Raheman M. Abdul
Raheman M. Abdul earned 200 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
There are many software programs on offer that will claim to magically speed up your computer. The best advice I can give you is to avoid them like the plague, because they will often cause far more problems than they solve. Try some of these "do it…
This Micro Tutorial will go in depth within Systems and Security in Windows 7 and will go into detail regarding Action Center, Windows Firewall, System, etc. This will be demonstrated using Windows 7 operating system.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Suggested Courses

609 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