what do you mean it fails?
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
#include <iomanip>
#include <iostream>
#include <dirent.h>
#include <fstream>
#include <string>
using namespace std;
int main()
{
DIR *dirp;
struct dirent *entry;
int pos;
int linecount = 0;
if(dirp = opendir("C:\\csvfiles\\"))
{
while(entry = readdir(dirp))
{
//printf("%s\n", entry->d_name); //prints the files in the directory
string temp = entry->d_name;
temp = "C:\\csvfiles\\" + temp;
if (temp.length() > 2) //skips over the . and .. entries
{
ifstream inFile; //creates a fstream object inFile
inFile.open(temp.c_str()); //opens the file
if (!inFile.is_open()) //if file wasn't opened
{
cout << "Failed to open " << entry->d_name << endl;
// return 1;
}
else
{
cout << "Successfully opened " << entry->d_name << endl;
}
inFile.clear();
inFile.close();
} //end of while file exists
}
closedir(dirp);
}
system("pause");
return EXIT_SUCCESS;
}
untested
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
please can you mark this thread as solved.
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
so just curious...any idea why it would work for some and not all? i mean the code works now but i'm still a bit curious why it didn't work for everything.
The reason why it worked on some is that you must have these files:
Successfully opened 5A40 Combo.csv
Successfully opened 5A40 Head.csv
Successfully opened 5A80 Combo.csv
Successfully opened 5A80 Head.csv
within your debug folder? I'm guessing.
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
No probs sometimes you hit a brick wall and you miss the obvious.
You might wanna look into why I had to use c_str() for reading in the paths...
iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439