Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Lets say I have a folder or a directory full of .zip files. Maybe it's C:\usr\ron\. I want to make a list to say exactly what is in that directory of zips. How can I make C read files from a directory And then print that name.
I can print a list and save that list, but I don't know how to scan a directory. Thanks

I know this is more complicated than it should be, but it just might work.
Couldn't you run a system command (assuming windows and dos here) and send the output to a file? Then you could open that file and scan for the name.
I know it's roundabout, but it might work...
+jestar

what u can do is call the DOS interrupts in ur C program to see all the files of ur directory u specify......
one of the methods is to use the interrupt that allows u to search particular files(file attributes don't matter)and then search for " *.* "......i don't remember the interrupt number which u call to use this , but i can provide u with the no. if u get in touch with me.....

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I think Jag means something like this:
#include
#define MAXFILES 500
main() {FILE *fptr;
int count = 0;
char strpath[60] = "cd ", strfile[81][MAXFILES];
printf("Enter path:([drive:][path]):\n");
scanf("%s", &strpath[3]);
system(&strpath);
system("dir /b > ZZZZ.ZZZ");
fptr = fopen("ZZZZ.ZZZ", "r");
while(fgets(strfile[count++], 80, fptr) != NULL);
fclose(fptr);
system("del ZZZZ.ZZZ"); // delete zzzz.zzz, not part of origional dir
// you now have an array of files strfile[]count = count - 3;
do
printf("%s", strfile[count]);
while(--count >= 0);
return 0;}

Good. But not quite it. I think I can figure it out from here though. Lets say I have this sentance.
"I have '_______' in my windows directory."
I want to put each file name in the directory inside that sentance on the line. So it would read."I have 'win.com' in my windows directory."
"I have 'win.ini' in my windows directory."
"I have 'user.dat' in my windows directory."
"I have 'cntrl.dat' in my windows directory."
"I have 'color.ini' in my windows directory."
"I have '_wns.pls' in my windows directory."
"I have 'whatever' in my windows directory."
"I have 'whatever' in my windows directory."
"I have 'whatever' in my windows directory."
I will try and get it from here. I'm not captain program, but I'll make something work.

Use findfirst() and findnext() functions that are provided in Turbo C V2.0 and later versions of Turbo C++

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |