Hi All,
I want to read a several (2000) files in a folder. I did as follows,
class for Readdir,
member function coding,Code:class Readdir { private: string dirName; public: Readdir ( const string& m) { dirName = m; } ~Readdir() {} void readFiles() const; };
main,Code:#include <dirent.h> #include <errno.h> void Readdir::readFiles () const { DIR* dirp; string buff; struct dirent* dp; dirp = opendir( dirName.c_str()); if (!dirp) { cout<< "Error: failure opening directory! " << endl; exit(1); } errno = 0; ofstream output; output.open("driftdata/drift", ios::out); while((dp = readdir (dirp))!=NULL) { if(strstr (dp->d_name, ".dat")) { ifstream input(dp->d_name); int lineno=0; while(getline(input, buff)) { if((++lineno%25)==5) { if(lineno ==4055) break; output<<buff<<endl; } } } if(errno) { cout << " Error :readdir () failure" << endl; exit(1); } } output.close(); closedir (dirp); }
In this case, my coding is working in linux OS (gCC compiler). But I want to run the codes in Windows OS ( Visual Studio).Code:int main(void) { Readdir myDir("."); myDir.readFiles(); return 0; }
Please tell me how can I do the above task in Windows.
The main problem is <dirent.h> header file is available in windows.
Please suggest me a different way to read files in a folder.
Thanks a lot in advance.




Reply With Quote