I have a script to abstract a .txt files end with (*.dly).
My problem is, I had to repeat the task by changing the file name manually. I need to abstract 100 files in a folder. Can somebody show me how to change my script so it can read multiple files in a folder. The files will end with .dly (which is readable in txt). The program will write it to .txt files after abstract some data from that files.

Below is my script:

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
string number,number2;
ifstream input;
ofstream output;

input.open ("aaxzi_temp_2000.dly");
output.open ("aaxzi_temp_2000.txt");

for (int j=1;j<=360;j++)
for (int k=1;k<=1;k++)
number2 = number;
input >> number;
} while (number != "9999.99" || number2 != "is");

//Which number
for (int i=0;i<2505;i++)
input >> number;

output << number << " ";
output << endl;
system ("pause");
return 0;


This is my script for 1 file. I need to abstract hundreds of files in a folder. I hope somebody can help me, please... as I totally new to programming script.

Thank you for your time.... Cheers....

8 Years
Discussion Span
Last Post by Ancient Dragon

use functions _findfirst() and _findnext() to locate all the file names. click this

struct _finddata_t c_file;
long hFile;

if ( (hFile = _findfirst("*.dly", &c_file)) == -1L )
     cout << "No *.dly files in current directory\n";
          std::string name = c_file.name.
          input.open ((string)(name + ".dly").c_str());
          output.open ((string)(name + ".txt").c_str());
          // rest of your code goes here
     } while ( _findnext(hFile, &c_file) == 0 )
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.