473,288 Members | 1,743 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,288 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 1420
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:...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.