LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 07-13-2004, 08:37 AM   #1
jupe
LQ Newbie
 
Registered: Jul 2004
Posts: 2

Rep: Reputation: 0
after readdir how can I open all the files


I did that. But now I can't open the files in my directory. Is anybody knows how to do it




#include <sys/types.h>
#include <dirent.h>
#include <stdio.h>

int main( int argc, char ** argv )
{
DIR * dir = opendir("My_path_dir");
if( dir )
{
dirent * entry;
while( entry = readdir( dir ) )
{
printf("%s\n",entry->d_name);
}
return 0;
}
else
{
printf("Couldn't open dir");
return -1;
}
int closedir(DIR * dir);
}
 
Old 07-13-2004, 09:00 AM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 53
In that printf() block of code you can just do:
Code:
sprintf(buf, "%s/%s", my_path_dir, entry->d_name);
fp = fopen(entry->d_name, "r");
/* Do whatever you need to do with the file */
fclose(fp);
You'll have to define buf and fp of course
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Regarding readdir r_213 Linux - Networking 2 01-15-2005 07:56 AM
Open Office does not open large files linuxfond Linux - Newbie 8 09-26-2004 03:46 AM
readdir then read the files jupe Programming 2 07-13-2004 10:04 AM
Can Open Office open WordPerfect files hemenm Linux - Software 2 03-10-2004 05:14 PM
using readdir to display files sutho1 Programming 2 10-10-2003 09:09 PM


All times are GMT -5. The time now is 02:51 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration