VasquezPL 0 Junior Poster

Ok...
Here is the problem..
Void extract_data is used to choose number of paramets I want to extract from Active directory...
For exmaple...I choose SAMID, Telephone Number, Manager name...But number of functions may vary...from one to all shown in the menu...

Void extract_data2() is used to use all data gathered at void extract_data
It uses system() statement to run dsget command to get the data we have choosen at extract_data menu...
so if we choose Telephone,manager,samid,display name...dsget DOS command will return 4 files...extract_data2 will ask us for name of file with input data(user names), will process it multiple times with dsget command and return us 4 files telephone.txt manager.txt samid.txt and display_name.txt
Ofcourse the number of files may also vary...It depends on how many options you choose at menu...if I choose 10 functions, extract_data2 will return 10 files with corresponding names..and it works really fine...
but I need now to merge all generated files into one csv files..
So if i choose Telephone,manager,samid,display name and then get 4 result filestelephone.txt manager.txt samid.txt and display_name.txt -> i need to merge them into one CSV. which sould look like that.

1st line from telepone.txt,1st line from manager.txt,1st line from samid.txt,1st line from display_name.txt...
2nd line,2nd line,2nd line,2nd line..
.
.
.
until EOF..

So whats the problem?
I dont know how to open diffrent number of files at once (depending on number of options choosen in menu)...and then to merge all into csv...
I know how to do that when i know the number of files...
for exqample:

while (! superv.eof() & ! nazwiska.eof())
                                              {
                                              getline (superv,line1);
                                              getline (nazwiska,line2);
                                              result << line1 << "," << line2 << endl;

but how to do that when number of files is always diffret,and number of getlines is diffrent to?

Please help!

Codes below:

void extract_data()
{

     char * opcje1[] = {"DN","NAME","SID","DISPLAY NAME","DESCRIPTION","OFFICE","TELEPHONE","EMAIL","MOBILE PHONE","IP PHONE","MANAGER","TITLE","DEPARTAMENT","HOME DIR","REMOVE","DONE","BACK"};
     string zmienna1;
     char input[ 45 ];
     i=0;
     bool wyjscie;
     wyjscie=0;
     system ("cls");
     gotoxy(1,15); cout << "Choose";
     while (wyjscie !=1)
     {
     system ("cls");
     gotoxy(1,1); cout << "to extract: ";
     //wyswietla opcje
     wyswietl(i);
     // koniec wyswietlania
     switch ( menu(opcje1, 17))
     {
                case 1: // DN
                i++;
                flag[i]="dn";
                option[i]="DN";
                break;

                case 2: // NAME
                i++;
                flag[i]="samid";
                option[i]="NAME";
                break;

                case 3: // SID
                i++;
                flag[i]="sid";
                option[i]="SID";
                break;
                
                case 4: // DISPLAY NAME
                i++;
                flag[i]="display";
                option[i]="DISPLAY_NAME";
                break;
                
                case 5: // DESCRIPTION
                i++;
                flag[i]="desc";
                option[i]="DESCRIPTION";
                break;
                
                case 6: // OFFICE
                i++;
                flag[i]="office";
                option[i]="OFFICE";
                break;
                
                case 7: // TELEPHONE
                i++;
                flag[i]="tel";
                option[i]="TELEPHONE";
                break;
                
                case 8: // EMAIL
                i++;
                flag[i]="email";
                option[i]="EMAIL";
                break;
                
                case 9: // MOBILE PHONE
                i++;
                flag[i]="mobile";
                option[i]="MOBILE_PHONE";
                break;
                
                case 10: // IP PHONE
                i++;
                flag[i]="iptel";
                option[i]="IP_PHONE";
                break;
                
                case 11: // MANAGER
                i++;
                flag[i]="mgr";
                option[i]="MANAGER";
                break;
                
                case 12: // TITLE
                i++;
                flag[i]="title";
                option[i]="TITLE";
                break;
                
                case 13: // DEPARTAMENT
                i++;
                flag[i]="dept";
                option[i]="DEPARTAMENT";
                break;
                
                case 14: // HOME DIR
                i++;
                flag[i]="hmdir";
                option[i]="HOMEDIR";
                break;
                
                case 15: // REMOVE
                i--;
                flag[i].empty();
                break;
                
                case 16: // DONE
                wyjscie=1;
                extract_data2();
                
                case 17: // BACK
                wyjscie=1;
                break;
                
                default:
                Beep(1000, 200);
            }
            }
}
void extract_data2()
{
    temp_delete();
    system("cls");
    string line,filename,filename1,c0,c1,c2,c3,c4,c5,c6;
    string opcje[30];
    string token;
    string filename_token;
    int n,h;
    h=0;
    cout << "Please enter filename: ";
    cin >> filename;
    ofstream wynik ("raport.csv");
    for(n=1; n<i+1 ; n++)
             {
             wynik << option[n] << ";";
             }
    wynik << endl << endl;
    ifstream plik_wejsciowy (filename.c_str());
    if (plik_wejsciowy.is_open())
             {
             cout << "\nProccesing file...\n";
             while (! plik_wejsciowy.eof() )
                      { // jedzie po linijce i wywala loginy z spacjami do loginy.txt
                      getline (plik_wejsciowy,line);
                      if (line == "") continue; // to ma niby puste linie spacje omijac
                      c1="@dsquery user -name ";
                      c2=" | dsget user -samid | findstr /v samid | findstr /v dsget>>loginy.txt";
                      c0=c1+'"'+line+'"'+c2;
                      system(c0.c_str());
                      } // koniec wywalania do loginy.txt
             ifstream loginy ("loginy.txt");
             ofstream bezspacji ("temp1.txt");
             while (! loginy.eof() )
                   {
                   getline (loginy,line);
                   if (line == "") continue; // to ma niby puste linie spacje omijac
                   trim2(line); //tutaj wycina spacje
                   bezspacji << line << endl;  //zapisuje do pliku grupy bez spacji
                   }
                   bezspacji.close();
                   ifstream loginy_bezspacji ("temp1.txt");
                   while (! loginy_bezspacji.eof())
                                          {
                                          getline (loginy_bezspacji,line);
                                          if (line == "") continue; // to ma niby puste linie spacje omijac
                                          c1="@dsquery user -samid ";
                                          c2=">>logins_loc.txt";
                                          c0=c1+'"'+line+'"'+c2; //wyciagamy lokacje
                                          system(c0.c_str());
                                          } // koniec wywalania do logins_loc.txt
                      loginy_bezspacji.close();
                      ifstream lokacje("logins_loc.txt");
                      while (! lokacje.eof())
                                          { //extract all chosen options and gives corresponding txt file with data we need.
                                          getline (lokacje,line);
                                          if (line == "") continue; // to ma niby puste linie spacje omijac
                                          for(n=1; n<i+1 ; n++)
                                                    {
                                                    c0="dsget user "+line+" -"+flag[n]+" | findstr /v dsget | findstr /v "+flag[n]+">>"+option[n]+".txt";
                                                    system(c0.c_str());
                                                    }
                                          } //
                      lokacje.close();
// THERE SHOULD BE FUNCTION TO MERGE ALL INFO UP TO 1 CSV FILE..MINE DOESNT WORK
                      ifstream plik_wejsciowy (filename.c_str());

                                   for(n=1; n<i+1 ; n++)
                                            {
                                            filename1==option[n]+".txt";
                                            token==option[n];
                                            ifstream token (filename1.c_str()); //We open all files
                                            while (! token.eof())
                                                  {
                                                  getline (token,line);
                                                  wynik << line << ";";
                                                  cout << line << endl;
                                                  }
                                            }
                                   wynik << endl;
                      
                      loginy.close();
                      wynik.close();
                      done();
                      system ("raport.csv");
                      return;
                      }
                      else czerwony();
                      cout << "Unable to open file";
                      bialy();
                      Sleep(1400);
                      return;
}