Solved

How to check if a folder is empty

Posted on 2006-07-11
4
3,565 Views
Last Modified: 2011-02-04
Is there a way to check if a folder is empty and putting up a messagebox if it is? I will not know the names of the files that will be in the folder.
Thanks!
0
Comment
Question by:boukaka
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 18

Accepted Solution

by:
Ravi Singh earned 250 total points
ID: 17082941
using System.IO;

...

string folderPath = @"C:\Temp";

if (Directory.GetFiles(folderPath).Length == 0)
{
      MessageBox.Show(folderPath + " is empty");
}
0
 
LVL 18

Expert Comment

by:Ravi Singh
ID: 17083006
if the folder may have subdirectories, you can check that by calling GetDirectories.

string folderPath = @"C:\Temp";

if (Directory.GetDirectories(folderPath).Length == 0 && Directory.GetFiles(folderPath).Length == 0)
{
      MessageBox.Show(folderPath + " is empty");
}
0
 

Author Comment

by:boukaka
ID: 17083355
Awesome, thank you!
0
 

Expert Comment

by:sqlDude170
ID: 34816384
Excellent example...perfect
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 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