can we read folders using C program?

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: May 2008
Posts: 2
Reputation: tejapedada is an unknown quantity at this point 
Solved Threads: 0
tejapedada tejapedada is offline Offline
Newbie Poster

can we read folders using C program?

 
0
  #1
May 30th, 2008
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.........
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 1,668
Reputation: jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of 
Solved Threads: 123
jephthah's Avatar
jephthah jephthah is offline Offline
Posting Virtuoso

Re: can we read folders using C program?

 
0
  #2
May 30th, 2008
the <dirent.h> library has the following functions
  1. int closedir(DIR *);
  2. DIR *opendir(const char *);
  3. struct dirent *readdir(DIR *);
  4. int readdir_r(DIR *, struct dirent *, struct dirent **);
  5. void rewinddir(DIR *);
  6. void seekdir(DIR *, long int);
  7. long int telldir(DIR *);
http://www.opengroup.org/onlinepubs/.../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"));



.
Last edited by jephthah; May 30th, 2008 at 5:59 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,117
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 282
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: can we read folders using C program?

 
1
  #3
May 31st, 2008
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.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 2
Reputation: tejapedada is an unknown quantity at this point 
Solved Threads: 0
tejapedada tejapedada is offline Offline
Newbie Poster

Re: can we read folders using C program?

 
0
  #4
Jun 2nd, 2008
Originally Posted by WaltP View Post
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,
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,117
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 282
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: can we read folders using C program?

 
0
  #5
Jun 6th, 2008
Look into findfirstfile and findnextfile .
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC