Solved

Get list of nonempty directories

Posted on 2014-12-24
7
253 Views
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.
0
Comment
Question by:Rothbard
7 Comments
 
LVL 24

Expert Comment

by:NVIT
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?
0
 

Author Comment

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

Expert Comment

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

Open in new window

0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 
LVL 9

Accepted Solution

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

Author Comment

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

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
0
 

Author Closing Comment

by:Rothbard
ID: 40516959
Thanks!
0

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 procedure for exporting installed hotfix details of remote computers using powershell
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …

680 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