Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Number of files

Status
Not open for further replies.

MrChopper

Programmer
Aug 11, 2004
20
US
Hi all-

Can someone point me in the right direction as to finding the number of files in a specified folder? I've seen a few examples via google, but the ones that are 2003 (Version I have) aren't really what I'm looking for. I basically want to find out how many files are in a folder (including subfolders), and use that count as an index in a progress bar control. Thanks in advance for the assistance!
 
To get the number of files in a folder:
Code:
System.IO.Directory.GetFiles("C:\MyFolder").Length
To get the number of files in a folder, including all subfolders:
Code:
System.IO.Directory.GetFiles("C:\MyFolder", "*.*", System.IO.SearchOption.AllDirectories).Length
 
Hi Chip

Directory.GetDirectories (using the same search pattern and option) doesn't include these directories in it's count, so I would expect GetFiles to similarly ignore them, but I don't know for sure.

Don't they hark back to DOS, to signify the directory itself and it's parent ?
 
If you remember CP/M you must be old.

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top