Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On a Windows 2003 Server I have an application that processes requests and stores them in a folder as a queue where a second process comes and processes these stored requests. However at times the number of files tend to reach 100,000.

Using Windows Explorer or even dir at the command prompt doesn't seem to be much of a solution for me to find out how many files there are stored. It also takes too much time, CPU and I/O.

Any suggestions?

share|improve this question

I'm not sure how fast this will work on a folder that big, but it's worth trying.

Save the code below in a .vbs file. Then, run it from a CMD prompt like this:

CSCRIPT FileCount.vbs C:\Insert\Your\Path\Here.

It only counts the file in the root of the path, but it could be modified to include sub-folders.

Dim oArgs
Set oArgs = WScript.Arguments

If oArgs.Count >= 1 Then
   WScript.Echo FileCount(oArgs(0))   
End If

Function FileCount(sPath)
   Dim oFSO
   Dim oFolder
   Dim oFiles

   Set oFSO = CreateObject("Scripting.FileSystemObject")
   Set oFolder = oFSO.GetFolder(sPath)
   Set oFiles = oFolder.Files
   FileCount = oFiles.Count
End Function
share|improve this answer

You could use the script on this page and call it this way:

 call filecount.bat C:\temp filecount /S
 echo %filecount%

The switch "/S" is needed if you want to recursively search in all subfolders

share|improve this answer
up vote 0 down vote accepted

Well in this case, if there are no built-in utilities that can help I wrote this little bugger:

using System; using System.IO;

namespace FileCount
    class Program
        static void Main(string[] args)
            var files = Directory.GetFiles(".");

but I hoped I didn't have to do this. Thanks to all of you :)

Update : I forgot to say it's in .NET (any version) and the language is C#.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.