Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File count from a folder

Tags:

c#

asp.net

How do I get number of Files from a folder using ASP.NET with C#?

like image 625
Sreejesh Kumar Avatar asked Feb 11 '10 05:02

Sreejesh Kumar


1 Answers

You can use the Directory.GetFiles method

Also see Directory.GetFiles Method (String, String, SearchOption)

You can specify the search option in this overload.

TopDirectoryOnly: Includes only the current directory in a search.

AllDirectories: Includes the current directory and all the subdirectories in a search operation. This option includes reparse points like mounted drives and symbolic links in the search.

// searches the current directory and sub directory int fCount = Directory.GetFiles(path, "*", SearchOption.AllDirectories).Length; // searches the current directory int fCount = Directory.GetFiles(path, "*", SearchOption.TopDirectoryOnly).Length; 
like image 167
rahul Avatar answered Nov 01 '22 04:11

rahul