Solved

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

Posted on 1998-08-10
10
255 Views
Last Modified: 2010-04-15
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.
0
Comment
Question by:sephi
10 Comments
 
LVL 10

Expert Comment

by:rbr
ID: 1251997
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
 
LVL 10

Expert Comment

by:rbr
ID: 1251998
If you have problems with your findfirst, findnext programm pls post your code.
0
 

Author Comment

by:sephi
ID: 1251999
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
 
LVL 3

Expert Comment

by:elfie
ID: 1252000
what about just executing, and intercepting the output of
"DIR /S" ? (not knowing NT, just unix)
0
 
LVL 1

Expert Comment

by:nilos
ID: 1252001
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
New My Cloud Pro Series - organize everything!

With space to keep virtually everything, the My Cloud Pro Series offers your team the network storage to edit, save and share production files from anywhere with an internet connection. Compatible with both Mac and PC, you're able to protect your content regardless of OS.

 

Author Comment

by:sephi
ID: 1252002
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
 

Accepted Solution

by:
vividh earned 200 total points
ID: 1252003
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
 

Author Comment

by:sephi
ID: 1252004
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
 
LVL 10

Expert Comment

by:rbr
ID: 1252005
So why did you accept the answer?
0
 

Author Comment

by:sephi
ID: 1252006
Is there a way to undo the acceptance?
0

Featured Post

Do email signature updates give you a headache?

Constantly trying to correctly format email signatures? Spending all of your time at every user’s desk to make updates? Want high-quality HTML signatures on all devices, including on mobiles and Macs? Then, let Exclaimer solve all your email signature problems today!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
memory mapped I/O query 6 142
Microsoft vcsetup.exe and vcssetup.exe 8 413
negation in C function 14 144
SQL handling single and double quotes 3 94
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now