Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 404
  • Last Modified:

Get list of nonempty directories

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
Rothbard
Asked:
Rothbard
2 Solutions
 
NVITCommented:
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
 
RothbardAuthor Commented:
To clarify, I need a list of all the directories in the home directory which have a nonempty subdirectory called Orders.
0
 
NVITCommented:
for /f "tokens=*" %a in ('dir /a-d /s') do @echo %a | find /i "Directory"

Open in new window

0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

 
SeanSystem EngineerCommented:
Powershell:
$a = Get-ChildItem "C:\Folder" -Filter Orders -Recurse
$a | Where-Object {$_.GetFiles().Count -ge 1} | Select-Object FullName
0
 
RothbardAuthor Commented:
Thanks Zindel1. By the way, how is it possible to output the list to a file (as it is very long)?
0
 
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
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
 
RothbardAuthor Commented:
Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now