Solved

Get list of nonempty directories

Posted on 2014-12-24
7
238 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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 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
0
 

Author Closing Comment

by:Rothbard
ID: 40516959
Thanks!
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

This article will help you understand what HashTables are and how to use them in PowerShell.
Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
This Micro Tutorial will teach you the basics of configuring your computer to improve its speed. It will also teach you how to disable programs that are running in the background simultaneously. This will be demonstrated using Windows 7 operating…
This Micro Tutorial will teach you how to change your appearance and customize your Windows 7 interface to your unique preference. This will be demonstrated using Windows 7 operating system.

770 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