A simple way to find the number of files under a directory

I'm looking for a simple way to get the number of files an NTFS directory has. Currently, I'm looping with findnext on all the files in the directory, opening each file's catalog and it is quite heavy.
The environment is Visual C++ 5.0 under WindowsNT 4.0.
sephiAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
vividhConnect With a Mentor Commented:
Exec the command DIR /s for the directory and open a pipe using popen(as in standard unixes) to read its output. Keep reading the output in a buffer till NULL. You will get the name of the file one at a time. If you want a unix like code I can pass it to you. Please drop me a e-mail at vividh@hotmail.com

0
 
rbrCommented:
I think that findfirst findnext would be the easiest way to get the numbers of file in your directory even it will take some time. Another way is to access the file tree directly but this will be much more complicated.
0
 
rbrCommented:
If you have problems with your findfirst, findnext programm pls post your code.
0
Turn Raw Data into a Real Career

There’s a growing demand for qualified analysts who can make sense of Big Data. With an MS in Data Analytics, you can become the data mining, management, mapping, and munging expert that today’s leading corporations desperately need.

 
sephiAuthor Commented:
findfirst works fine, but I need to loop on all the files in the directory. I'm looking for a way (possibly more complicated to program) to read the directory catalog only and get the file count from there.
0
 
elfieCommented:
what about just executing, and intercepting the output of
"DIR /S" ? (not knowing NT, just unix)
0
 
nilosCommented:
There is no way to do what you want except find first / next. This can be demonstrated when you try to delete a HUGE directory, full of files, using the Explorer or a plain CMD Del (Deltree is not available in NT). NT, by itself took 30 minutes to delete the Platform SDK and, of course, I'm not using the, useless, trash can.



0
 
sephiAuthor Commented:
The answer I hope to get is the structure of the directory catalog. If I "read" the directory itself, what do I get in the buffer? (this is the way you get directory info in Unix).
0
 
sephiAuthor Commented:
vividh and elfie's suggestion to use the "DIR" command, sounds simple, but the question is how does the DIR command find all the files. It probably uses findfirst/findnext itself, which we already do.

My initial question is, therefore, still open: Can I "read" in some way the directory catalog and get from there, the number of subdirectories and files that lie undeneath this directory?
0
 
rbrCommented:
So why did you accept the answer?
0
 
sephiAuthor Commented:
Is there a way to undo the acceptance?
0
All Courses

From novice to tech pro — start learning today.