To count number of files in the folder.

Gopesh9
Posted by Gopesh9 under ASP.NET category on | Points: 40 | Views : 1235
Here is a simple example showing how you can count the number of files in folder.

public static int numberOfFiles;
public static int fileCount(string filePath, string file_Extension)
{
string[] fileDir = Directory.GetFiles(filePath);
foreach (string files in fileDir)
{
string fileName = files.Substring(filePath.Length + 1);
string[] fileExtension = fileName.Split('.');
if (fileExtension[1] == file_Extension)
{
numberOfFiles = numberOfFiles + 1;
}
}
return numberOfFiles;
}

Comments or Responses

Login to post response