How to check if Directory has Files in C# and VB.NET

To check if Directory has Files in C# and VB.NET you can use the following snippet.

Sample C#

public static bool HasFilesInFolder(DirectoryInfo folder)
{
	return folder.GetFiles("*.*").Any();
}

Sample VB.NET

Public Shared Function HasFilesInFolder(folder As DirectoryInfo) As Boolean
	Return folder.GetFiles("*.*").Any()
End Function

Please Share us:
Please rate this snippet

One thought on “How to check if Directory has Files in C# and VB.NET

Leave a Reply