.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Imran Ghani
Sohaib Khalid

Post New Resource Bookmark and Share   

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

Posted By:Narayanan       Posted Date: February 26, 2012    Points: 40    Category:    URL: http://www.dotnetspark.com  

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");


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


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend