No of files in the Folder in Particular file Type in the C#.Net

Naraayanan
Posted by Naraayanan under C# category on | Points: 40 | Views : 1109
The following function returns no of files in the particular in the particular folder in the C#.net
Declaration part:
       public static int chknofiles;


Function Part:
public static int countoffiles(string filepath, string fileextension)
{

string[] fsDir = Directory.GetFiles(filepath);
foreach (string f in fsDir)
{
string fName = f.Substring(filepath.Length + 1);
string[] fileExt = fName.Split('.');
if (fileExt[1] == fileextension)
{
chknofiles = chknofiles + 1;
}
}

return chknofiles;
}



How to use this function in the C#.net ?

int chkvalue = countoffiles(txtBrowsFile.Text, "txt");
MessageBox.Show(chkvalue.ToString());


Here, Chkvalue is an object.
countoffiles is a function
txtBrowseFiles.Text is a Input value(Specify the Path)
txt is a file extension.

Comments or Responses

Login to post response