Third time lucky:
Code:#include <fstream> #include <iostream> #include <dirent.h> #include <sys/stat.h> using namespace std; struct dirent *dirp; struct stat filestat; string dir, ImportPath, ExportPath, LineData; DIR *dp; ifstream FileIn; ofstream FileSave; int main() { cout << "Please enter the directory to process: " << flush; getline(cin, dir); dp = opendir (dir.c_str() ); if (dp == NULL) { cout << "Error(" << errno << ") opening " << dir << endl; return errno; } while ((dirp = readdir (dp))) { //A ImportPath = dir + "/" + dirp->d_name; if (stat( ImportPath.c_str(), &filestat)) continue; if (S_ISDIR( filestat.st_mode )) continue; ExportPath = dirp->d_name; FileSave.open(ExportPath.c_str() ); FileIn.open(ImportPath.c_str() ); cout << ExportPath; if(FileIn.is_open()) { //B cout << " open" << endl; while(FileIn.good()) { //C getline (FileIn, LineData); cout << LineData << endl; FileSave << LineData; //I have some more code here to control strings on each line } //C FileIn.close(); } //B else { cout << "File is not open" << endl; } FileSave.close(); } //A closedir( dp ); system("PAUSE"); return EXIT_SUCCESS; }




:
Reply With Quote
