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

Posted by Naraayanan under C# category on | Points: 40 | Views : 1456
The following function returns no of files in the particular in the particular folder in the
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 ?

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

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