Computing.Net > Forums > Programming > Scan Directory With C

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Scan Directory With C

Reply to Message Icon

Name: John Ellington
Date: February 6, 2002 at 17:49:03 Pacific
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: jag mafer
Date: February 6, 2002 at 20:24:56 Pacific
Reply:

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


0

Response Number 2
Name: John
Date: February 6, 2002 at 22:34:07 Pacific
Reply:

I'm not sure I get your meaning?



0

Response Number 3
Name: vikhyat
Date: February 7, 2002 at 05:25:18 Pacific
Reply:

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.....


0

Response Number 4
Name:  
Date: February 7, 2002 at 19:53:27 Pacific
Reply:


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;

}


0

Response Number 5
Name: John Ellington
Date: February 8, 2002 at 00:26:38 Pacific
Reply:

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.


0

Related Posts

See More



Response Number 6
Name: SURESH
Date: February 10, 2002 at 00:59:44 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Scan Directory With C

Help with C www.computing.net/answers/programming/help-with-c/10733.html

make folder with C www.computing.net/answers/programming/make-folder-with-c/500.html

window based appilcations with C www.computing.net/answers/programming/window-based-appilcations-with-c/7759.html