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

Top 5 Contributors of the Month
Gaurav Pal

Home >> Code Snippets >> File Operation >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

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: File Operation    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;

Coding Part:

     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
Find More code samples in C#, ASP.Net, Vb.Net and more Here

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