Help with Opening files
I am trying to open all the files in the directory to process them but the files are not opening.
Can anybody point out the errors in my code?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
void merge()
{
DIR *pDIR;
struct dirent *entry;
fstream outFile;
outFile.open("tokens.txt");
if(!outFile)
cout<<"File Not created"<<endl;
else
cout<<"File created"<<endl;
vector<string> files;
string read_dir_path1 = "/home/surya/workspace1/Neptune/tokens/";
if( pDIR=opendir(read_dir_path1.c_str() ) )
{
cout<<"\nDirectory Opened\n";
while(entry = readdir(pDIR))
{
if( strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0 )
{
//tokenize( entry->d_name, read_dir_path1 );
//cout<<entry->d_name<<endl;
files.push_back(entry->d_name);
//cout<<files.size()<<endl;
}
}
}
else
cout<<"Directory did not open"<<endl;
ifstream inFile;
for(int i=0;i<files.size();i++)
{
const char* temp1=files[i].c_str();
//cout<<files[i]<<endl;
//cout<<temp1<<endl;
inFile.open(temp1);
if(!inFile.good())
inFile.clear();
if(!inFile.is_open())
cout<<"Not opened"<<endl;
else
{
cout<<"opened"<<endl;
string temp;
while(!inFile.eof())
{
string line;
getline(inFile,line);
istringstream iss(line);
do
{
string r;
iss>>r;
outFile<<line;
outFile<<endl;
}while(iss);
}
}
inFile.close();
inFile.clear();
}
outFile.close();
outFile.clear();
}
|
I have been trying but I am unable to find out the error.
Topic archived. No new replies allowed.