Get the no of textfiles from a Directory

This code shows how to get number of textfiles from a direcory
In Config file specify source path :

for Ex:


<add key ="Filepath" value="D:\Temp\Test" />

In .CS file:


string strDirectoryPath =ConfigurationManager.AppSettings["Filepath"]; // Retrives the Directory Path

if (Directory.Exists(strDirectoryPath))
{


string[] strArrFiles = Directory.GetFiles(strDirectoryPath, "*.txt"); // Gets all the textfile from the Directory path

if (strArrFiles.Length > 0)
{

label1.Text=strArrFiles.Length + " File(s) found in the Directory!";

}
else
{
label1.Text="No File(s) in the Directory!";
}
}

else
{

label1.Text = strDirectoryPath +" doesnt Exists";
}


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: