hi.....
how to get all path names all files
in a perticular directory in C pgm.
plz tell me...and give some sample pgm.
Printable View
hi.....
how to get all path names all files
in a perticular directory in C pgm.
plz tell me...and give some sample pgm.
Hi,
'pgm' means programme I guess...
You can find information on the standard library functions here:
http://www.gnu.org/software/libc/man...Directory.html
Ahhm...the path name for all files in a particular directory would be:
particular_directory(/ or \)file
You don't even need a c program!
But if you meant "all path names (...) in a particular directory" (which would be the directories in the directory, I guess), you could look at dirent.h and readdir. You can get the file type of each file this way and determine if it is a directory.
If this gives you trouble, post to this thread again.
There's an FAQ about this, with an example of readdir() and friends, I believe.
http://faq.cprogramming.com/cgi-bin/...&id=1044780608
Example:
Code:#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
char buffer[256];
printf("Input a directory name: ");
fgets(buffer, sizeof(buffer)/2, stdin);
strtok(buffer, "\n");
snprintf(buffer + sizeof(buffer)/2, sizeof(buffer)/2, "ls \"%s\"", buffer);
system(buffer + sizeof(buffer)/2);
return 0;
}
That's just painful. You should put that code in your signature instead of the mere two-plus-buffer-overflow code. :)
[edit] I especially like
Very well done. [/edit]Code:strtok(buffer, "\n");
I shouldn't post code like that anymore. I am sometimes taken dangerously seriously and receive PMs such as "Code works great, but how do I capture its output?"