Mail Archives: djgpp/1998/11/05/11:40:13
On Thu, 05 Nov 1998 14:51:42 GMT, quazar AT freemail DOT co DOT za (Marc Brooker)
wrote:
>Hi,
>
>I need to write a simple program to count the files in a directory, I
>am currently using a program that is passed
>count *.*
>and it outputs the number of arguements, is there a better way to do
>this?
I don't know if it is better, but in a situation where I needed a
count (as well as other information) I used something like this:
---------start code snippet--------
int done,TotalCount;
struct ffblk f;
char Filter[]="*.*";
done=findfirst(Filter,&f,FA_ARCH|FA_RDONLY|FA_HIDDEN|FA_SYSTEM);
//count directory entries
while (!done)
{
++TotalCount;
done = findnext(&f);
}
----------end code-----------
Incidentally, looking in that program, I also noticed that I used this
function for checking if individual files exist:
#include <unistd.h>
int __file_exists(const char *_fn);
Hope that helps.
- Raw text -