473,385 Members | 1,521 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Identify empty sub-folders

In a given folder, there are many sub-folders. Is there an easy way to
find out those sub-folders that don't contain any file (empty sub-
folders)? Is there such a utility in .NET?

Jun 9 '07 #1
6 1423
Hello,

recurively iterate through the directories using Directory.GetDirectories().

In each folder call Directory.GetFiles().

Best regards,
Henning Krause

"Curious" <fi********@yahoo.comwrote in message
news:11**********************@c77g2000hse.googlegr oups.com...
In a given folder, there are many sub-folders. Is there an easy way to
find out those sub-folders that don't contain any file (empty sub-
folders)? Is there such a utility in .NET?
Jun 9 '07 #2
This does it:

using System.IO;

foreach (string dir in Directory.GetDirectories(<rootDir>, @"*",
SearchOption.AllDirectories))
{
if (Directory.GetFiles(dir).Length == 0)
{
// Folder empty
Console.WriteLine (dir);
}
}
Hope this helps.

"Curious" wrote:
In a given folder, there are many sub-folders. Is there an easy way to
find out those sub-folders that don't contain any file (empty sub-
folders)? Is there such a utility in .NET?

Jun 9 '07 #3
Henning, Siva,

Thanks for the good advice!

Curious

Jun 9 '07 #4
There's a problem - I used UNC path (\\crpapp01\\mastershare") as root
folder and got an error: Cannot find "C:\crpapp01\\mastershare"

I used UNC path while it seems to interprete it as local folder. Any
work-around?

Details-----------------------------------------------------------------------
foreach (string dir in Directory.GetDirectories("\\crpapp01\
\mastershare", @"*", SearchOption.AllDirectories))
{
if (Directory.GetFiles(dir).Length == 0)
{
// Folder empty
//Console.WriteLine (dir);
sw.WriteLine(dir + "\n");
}
}

Jun 9 '07 #5
Hello,

in C#, you must escape the backslash.

either use
Directory.GetDirectories(@"\\crpapp01\mastershare" , @"*",
SearchOption.AllDirectories))

or
Directory.GetDirectories("\\\\crpapp01\\mastershar e", @"*",
SearchOption.AllDirectories))

Best regards,
Henning Krause
"Curious" <fi********@yahoo.comwrote in message
news:11*********************@p77g2000hsh.googlegro ups.com...
There's a problem - I used UNC path (\\crpapp01\\mastershare") as root
folder and got an error: Cannot find "C:\crpapp01\\mastershare"

I used UNC path while it seems to interprete it as local folder. Any
work-around?

Details-----------------------------------------------------------------------
foreach (string dir in Directory.GetDirectories("\\crpapp01\
\mastershare", @"*", SearchOption.AllDirectories))
{
if (Directory.GetFiles(dir).Length == 0)
{
// Folder empty
//Console.WriteLine (dir);
sw.WriteLine(dir + "\n");
}
}
Jun 9 '07 #6
Thanks for the advice - It works!

Jun 10 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Robert A. van Ginkel | last post by:
Hello Fellow Developer, This looks like a long mail, but at the end of this post is my socket wrapper attached. I want to make a timeout procedure that starts counting down after the...
5
by: Tappy Tibbons | last post by:
I have a class I am serializing, and need the resultant XML to skip/omit classes that are not initialized, or their member variables have not been set. Is this possible? Say for the following...
6
by: Woody Splawn | last post by:
I know that I can do the following to identify the parent name of an active control Dim sParentName As String = ActiveControl.Parent.Name But how do I identify the name of the active control?...
7
by: Grahmmer | last post by:
I have a few timers that are added to a form at runtime. I can handle the event fine, but I cannot identify which timer fired. Is there a way to do this? Timer Creation: -------------...
10
by: Charles Hunt | last post by:
Hi, When running this code in VB2003 Sub guidtest() Dim gstring As String Dim gid As Guid
0
by: Asif Mohammed | last post by:
Hello, I have a datagridview bound to a database table with 2 columns. One is an ID column "NameID" which is hidden, the other is called "Name". The schema picture is here :...
0
by: Asif Mohammed | last post by:
Hello, I have a datagridview bound to a database table with 2 columns. One is an ID column "NameID" which is hidden, the other is called "Name". The schema picture is here :...
6
by: Pieter | last post by:
Hi, For some procedures that throws exceptions, I would like to show different messages to the user depending on what type of exception he's getting. For instance this one: when the file is...
2
by: ronchese | last post by:
I'm noticing this since I started developing a website project: my session variables are getting empty! I did a real easy test, and I checked my session variable is getting empty!! What is...
1
by: DrDavey | last post by:
What are the advantages/disadvantages of using a choice of a several "sub-"elements with empty content (and no attributes) vs. simple content. Here's an example: Using simple content:...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.