|
-
June 11th, 2007, 12:40 AM
#1
[RESOLVED] Reading multiple files in a folder
Hi All,
I have several files like name as follows,
res0001847.dat
res0001850.dat
res0001854.dat
res0001860.dat
Names are something like above which has numerical analysis data. So far I used following coding to read above data files in Linux OS.
Code:
#include <dirent.h>
#include <cerrno>
int readFiles(char * dirname)
{
DIR* dirp;
string buff;
struct dirent* dp;
dirp = opendir(dirname);
if ( !dirp ) {
cout << "Error: failure opening directory" << endl;
exit(1);
}
errno = 0;
ofstream output;
output.open("driftdata", ios::out);
while (( dp = readdir(dirp) )!=NULL) { // read directory
if(strstr(dp->d_name, ".dat")) { // to check dat files
ifstream input(dp->d_name); // to read files
int lineno=0;
while( getline(input, buff) ) { output << buff << endl; }
if ( errno ){
cout << "Error: readdir() failure!" << endl;
exit(1);
}
}
output.close();
closedir( dirp );
}
But now my problem is, I should work above task in a Windows OS (MS Visual Studio). How can I do?
Please help me!!!!!!!!!
Rgds,
Renuka.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|