Link to home
Start Free TrialLog in
Avatar of boukaka
boukakaFlag for Canada

asked on

How to check if a folder is empty

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!
ASKER CERTIFIED SOLUTION
Avatar of Ravi Singh
Ravi Singh
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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");
}
Avatar of boukaka

ASKER

Awesome, thank you!
Excellent example...perfect