Hi all,
using C language we can read text files. we can read each and every character.
ch =fgetc(filepointer);

but i want to know how to read folders.
for ex: fopen("c:\one foldername", "r");

in out put i want print subfolders and files.

if any body know please help me...

thanks in advance.........

Recommended Answers

All 4 Replies

the <dirent.h> library has the following functions

int            closedir(DIR *);
DIR           *opendir(const char *);
struct dirent *readdir(DIR *);
int            readdir_r(DIR *, struct dirent *, struct dirent **);
void           rewinddir(DIR *);
void           seekdir(DIR *, long int);
long int       telldir(DIR *);

http://www.opengroup.org/onlinepubs/007908799/xsh/dirent.h.html


if you're confined to Windows-specific solutions, theres an implementation of this for Windows
http://www.gimp.org/~tml/gimp/win32/dirent.zip

if that's not acceptable for homework purposes, then maybe you can just get away with a system call like strcpy(myBigString, system("dir")); .

It would be best to let us know what O/S and compiler you are using so we don't have to guess, as jephthah was forced to do. They all have different ways to accomplish the task.

commented: yup. i was just having a momentary bout of niceness :P +3

It would be best to let us know what O/S and compiler you are using so we don't have to guess, as jephthah was forced to do. They all have different ways to accomplish the task.

thanku for ur reply

i am working in windows. am using visual cpp environment

thanku,

Look into findfirstfile and findnextfile .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.