Hi,

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++)
{
do
{
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....

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";
else
{
    do
    {
          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 )
    _findclose(hFile);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.