Link to home
Start Free TrialLog in
Avatar of sorriv
sorriv

asked on

Accessing all files in a directory

I have the following code:

#include <fstream.h>
#include <iostream.h>
#include <string.h>
int main (int argc, char *argv[])
{
    argv[1] = "c:\\test2";
    argv[2] = "c:\\test2";
    char string[161];
    ifstream in(argv[1]);
         if(!in)                  
    {
         cout<<"File cannot be opened";            
         return 1;
    }
    ofstream out;
    out.open(argv[2]);        
    while(!in.eof())
    {
         in.getline(string,161);
         out << string << endl;
    }
    in.close();
    out.close();
       return 0;
}

This code is supposed to access all the files of *.txt (located in c:\\test2) and continue with the program. The program puts a carriage return after every 160 bits to make my .txt files look nice. However, I can only get this program to run and convert one .txt file at a time. I have ten files in my c:\test2 folder which I need all done at the same time or one after another. Can someone please help me or show me what I am missing. Thanks!
Avatar of cryptosid
cryptosid

heard about findfirst() and findnext() functions...these functions are present in DOS.H and they can be used to develop a simple loop which can give u the names of the files matching a specific pattern supplied to them...
here is how...

#include <dos.h>


void Search(char pattern[])
{
   //define a variable to hold the list of filenames...
   struct ffblk file;

   //specify the pattern to findfirst...
   if(findfirst(pattern,&file,FA_ARCH)==0)
   {
      //loop through the filenames till there are files // matching the pattern specified..
      do
      {
         printf("\nfile: %s",file.ff_fname);
         //here i have simply printed the names
         //you could open the files using the name and do whatever you want...got it...
      }while(findnext(&file)==0); //end of while loop
   }//end of if
}
//end of function

hope that helps
cryptosid
If you are using VC++ 6.0 :

#include <io.h> // for _findfirst and _findnext
...

int myFunction(char * in_file, char * out_file) {
   char string[161];
   ifstream in(in_file);

   if(!in)                  
   {
        cout<<"File cannot be opened";            
        return -1;
   }
   ofstream out;
   out.open(out_file);        
   while(!in.eof())
   {
        in.getline(string,161);
        out << string << endl;
   }
   in.close();
   out.close();

   return 0;
}

int search_dir(char * file_name) {
   struct _finddata_t c_file;
   long hFile;

   // if you want, you can use the value from  
   // file_name as a reference for your input
   // and output.
   // the code below perform search in it's,
   // where the .exe (the program) resides,
   // current directory.

   // Find first .txt file in current directory
   if( (hFile = _findfirst( "*.txt", &c_file )) == -1L ) {
      cout << "No *.txt files in current directory!\n";
      return -1;
   }
   else     {
      // get the file name and create a full path
      // you can use the "c_file.name" to get the file  
      // name.
      ...
      // call the function to manipulate the
      // current file.
      myFunction(in_file, out_file);
      ...
      // Find the rest of the .txt files
      while( _findnext( hFile, &c_file ) == 0 ) {
         // get the file name and create a full path
         // you can use the "c_file.name" to get the file  
         // name.
         ...
         // call the function to manipulate the
         // current file.
         myFunction(in_file, out_file);
         ...
      }
      _findclose( hFile );
   }
   return 0;
}

int main() {
   char file_name[161];

   strcpy(file_name, "c:\\test.txt");
   
   search_dir(file_name);
   return 0;
}

I have move your code inside the main() to another function myFunction(), so that you can perform the function of reading and writing inside the search_dir().

The above code will search for .txt file and manipulate the current .txt file and repeat the following process until no more .txt files found in the current directory.

If you are interested, you can also search for the .txt files in the subdirectories of the current directory too... but the current code couldn't accomplish that. need some modification to the code in search_dir().

For more information, refer to this link :

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_crt__find.2c_._wfind_functions.asp

Hope this will help too...

gotenks
Avatar of sorriv

ASKER

gotenks, I get the following error when I compile with your code.

error C2065: 'in_file' : undeclared identifier
error C2065: 'out_file' : undeclared identifier

Any suggestions?
Avatar of sorriv

ASKER

gotenks, I get the following error when I compile with your code.

error C2065: 'in_file' : undeclared identifier
error C2065: 'out_file' : undeclared identifier

Any suggestions?
of course, i didnt declare the in_file and out_file inside the search_dir()... you should declare it as :

char in_file[256]; // depend on what size you wished.
char out_file[256]; // depend on what size you wished.

and also you need to assign values to these 2 variables. before proceeding to call the myFunction().

example of in_file and out_file value would be :
in_file = "c:\\test\\file_name.txt";
out_file = "c:\\test\\file_name_out.txt";

hope this will help.
good luck.

gotenks
Avatar of sorriv

ASKER

gotenks, I get the following error when I compile with your code.

error C2065: 'in_file' : undeclared identifier
error C2065: 'out_file' : undeclared identifier

Any suggestions?
Avatar of sorriv

ASKER

gotenks, I get the following error when I compile with your code.

error C2065: 'in_file' : undeclared identifier
error C2065: 'out_file' : undeclared identifier

Any suggestions?
Avatar of sorriv

ASKER

gotenks..that helped a lot....now I am constantly getting an error that "File cannot be openedFile cannot be openedPress any key to continue"....There are two '.txt' files located in my 'c:\test' folder.....why else might I be getting this error? I have posted the revised code below if you would like to test yours.

#include <io.h> // for _findfirst and _findnext
#include <fstream.h>
#include <iostream.h>
#include <string.h>

char in_file[256];
char out_file[256];

int myFunction(char * in_file, char * out_file) {
  char string[161];
  ifstream in(in_file);

in_file = "c:\\test\\*.txt";
out_file = "c:\\test\\*.txt";

  if(!in)                  
  {
       cout<<"File cannot be opened";            
       return -1;
  }
  ofstream out;
  out.open(out_file);        
  while(!in.eof())
  {
       in.getline(string,161);
       out << string << endl;
  }
  in.close();
  out.close();

  return 0;
}

int search_dir(char * file_name) {
  struct _finddata_t c_file;
  long hFile;

  // if you want, you can use the value from  
  // file_name as a reference for your input
  // and output.
  // the code below perform search in it's,
  // where the .exe (the program) resides,
  // current directory.

  // Find first .txt file in current directory
  if( (hFile = _findfirst( "c:\\test\\*.txt", &c_file )) == -1L ) {
     cout << "No *.txt files in current directory!\n";
     return -1;
  }
  else     {
     // get the file name and create a full path
     // you can use the "c_file.name" to get the file  
     // name.
   
     // call the function to manipulate the
     // current file.
     myFunction(in_file, out_file);
     
     // Find the rest of the .txt files
     while( _findnext( hFile, &c_file ) == 0 ) {
        // get the file name and create a full path
        // you can use the "c_file.name" to get the file  
        // name.
       
        // call the function to manipulate the
        // current file.
        myFunction(in_file, out_file);
       
     }
     _findclose( hFile );
  }
  return 0;
}

int main() {
  char file_name[161];

  strcpy(file_name, "c:\\test\\*.txt");

    search_dir(file_name);
  return 0;
}



have make some changes to it, see if this help...

#include <io.h> // for _findfirst and _findnext
#include <fstream.h>
#include <iostream.h>
#include <string.h>

char in_file[256];
char out_file[256];

int myFunction(char * in_file, char * out_file) {
 char string[161];
 ifstream in(in_file);
 
 cout << "hello in " << in_file << endl;
 cout << "hello out " << out_file << endl;
//in_file = "c:\\test\\*.txt";
//out_file = "c:\\test\\*.txt";

 if(!in)                  
 {
      cout<<"File cannot be opened";            
      return -1;
 }
 ofstream out;
 out.open(out_file);        
 while(!in.eof())
 {
      in.getline(string,161);
      out << string << endl;
 }
 in.close();
 out.close();

 return 0;
}

int search_dir(char * file_path) {
 struct _finddata_t c_file;
 long hFile;

 char temp_path[256];
 char in_file[256];
 char out_file[256];

 // if you want, you can use the value from  
 // file_name as a reference for your input
 // and output.
 // the code below perform search in it's,
 // where the .exe (the program) resides,
 // current directory.

 strcpy(temp_path, file_path);
 strcat(temp_path, "*.txt");
 // Find first .txt file in current directory
 if( (hFile = _findfirst( temp_path, &c_file )) == -1L ) {
    cout << "No *.txt files in current directory!\n";
    return -1;
 }
 else     {
    // get the file name and create a full path
    // you can use the "c_file.name" to get the file  
    // name.
    strcpy(in_file, file_path);
    strcat(in_file, c_file.name);

    strcpy(out_file, file_path);
    strcat(out_file, c_file.name);
    // call the function to manipulate the
    // current file.
    myFunction(in_file, out_file);
   
    // Find the rest of the .txt files
    while( _findnext( hFile, &c_file ) == 0 ) {
       // get the file name and create a full path
       // you can use the "c_file.name" to get the file  
       // name.
       
       strcpy(in_file, file_path);
       strcat(in_file, c_file.name);

       strcpy(out_file, file_path);
       strcat(out_file, c_file.name);
       // call the function to manipulate the
       // current file.
       myFunction(in_file, out_file);
       
    }
    _findclose( hFile );
 }
 return 0;
}

int main() {
 char file_name[161];

 // just send the path/directory to search, instead of  
 // path and file name.
 strcpy(file_name, "e:\\practice\\test\\");

 search_dir(file_name);
 return 0;
}

I have also changed in the main(), the parameter that is sent to search_dir(). the code now send only the path to search for the .txt files... hope this helps... good luck.

gotenks
the error is because you pass in a wrong string of in_file and out_file

your value :
in_file = "c:\\test\\*.txt";
out_file = "c:\\test\\*.txt";

it should be :
in_file = "c:\\test\\ValidFileName.txt";
out_file = "c:\\test\\ValidFileName.txt";

when you assigned your value to the file input stream, in, it cannot find the "*.txt" file... that is the reason you get the error, i guess.
if your folder, c:\\test\\, have the following file :
   TextFile.txt
   OtherFile.txt
then you should write your in_file as :
in_file = "c:\\test\\TextFile.txt";

and
in_file = "c:\\test\\OtherFile.txt";


gotenks
Avatar of Mayank S
You are already passing the values to in_file and out_file from another function. Then please don't modify it anywhere in myFunction () like you've done.

Mayank.
Avatar of sorriv

ASKER

OK....this code here seems to run fine without any errors and places a test file into the correct folder, however, it does not manipulate all of the *.txt files by placing a carriage return every 160 characters. It originally did this. So if I can just get the original to work with what we now have I will be set. THANK YOU SO MUCH FOR WHAT YOU HAVE HELPED ME WITH SO FAR!

#include <io.h> // for _findfirst and _findnext
#include <fstream.h>
#include <iostream.h>
#include <string.h>

char in_file[256];
char out_file[256];

int myFunction(char * in_file, char * out_file) {
char string[161];
ifstream in(in_file);


if(!in)                  
{
     cout<<"File cannot be opened";            
     return -1;
}
ofstream out;
out.open(out_file);        
while(!in.eof())
{
     in.getline(string,161);
     out << string << endl;
}
in.close();
out.close();

return 0;
}

int search_dir(char * file_path) {
struct _finddata_t c_file;
long hFile;

char temp_path[256];
char in_file[256];
char out_file[256];

// if you want, you can use the value from  
// file_name as a reference for your input
// and output.
// the code below perform search in it's,
// where the .exe (the program) resides,
// current directory.

strcpy(temp_path, file_path);
strcat(temp_path, "*.txt");
// Find first .txt file in current directory
if( (hFile = _findfirst( "c:\\test", &c_file )) == -1L ) {
   cout << "No *.txt files in current directory!\n";
   return -1;
}
else     {
   // get the file name and create a full path
   // you can use the "c_file.name" to get the file  
   // name.
   strcpy(in_file, file_path);
   strcat(in_file, c_file.name);

   strcpy(out_file, file_path);
   strcat(out_file, c_file.name);
   // call the function to manipulate the
   // current file.
   myFunction(in_file, out_file);
   
   // Find the rest of the .txt files
   while( _findnext( hFile, &c_file ) == 0 ) {
      // get the file name and create a full path
      // you can use the "c_file.name" to get the file  
      // name.
     
      strcpy(in_file, file_path);
      strcat(in_file, c_file.name);

      strcpy(out_file, file_path);
      strcat(out_file, c_file.name);
      // call the function to manipulate the
      // current file.
      myFunction(in_file, out_file);
     
   }
   _findclose( hFile );
}
return 0;
}

int main() {
char file_name[161];

// just send the path/directory to search, instead of  
// path and file name.
strcpy(file_name, "c:\\test\\");

search_dir(file_name);
return 0;
}
not really sure if you can open the same file and perform the read and write at the same time...
however, if you want the file to be output to another file instead, try changing the out_file to another name. right now, you are using the same file name for input and output...

int search_dir(...) {
   ...
   strcpy(in_file, file_path);
   strcat(in_file, c_file.name);

   strcpy(out_file, file_path);
   strcat(out_file, "out_"); // added
   strcat(out_file, c_file.name);
   ...
}

now the in_file will hold the value : c:\test\filename.txt
and the out_file will hold the value : c:\test\out_filename.txt

see if this is what you want...

and one more thing... why you have hard coded the filepath : _findfirst("c:\\test", &c_file)?
as in :

if( (hFile = _findfirst("c:\\test", &c_file )) == -1L ) {
  cout << "No *.txt files in current directory!\n";
  return -1;
}


gotenks
>> not really sure if you can open the same file and perform the read and write at the same time...

Don't think that you can. I guess Cobol is the only language through which it is achieved in some manner. You can read a record, modify it and then use the 'rewrite' statement and it puts the updated record back into the file.... no fusses about read mode/ write mode, etc.

Mayank.
so, from what mayank had mentioned, since we cannot open the same file for input and output at the same time, i guess the better solution is to output the result to another file.
you can also keep the output to a buffer (not so practical, if the size is big) or write it to a temp file and then copy the content of temp file into that same file after you have finished reading it. finally, delete the temp file.
i have tried using fstream instead of ifstream, and ofstream but the most i can get is to append it, using the "ios::in | ios::out | ios::app" mode :

fstream in_out("c:\\temp.txt", ios::in | ios::out | ios:: app);

original file content :
hello world
good bye

output content :
hello world
hello world
good bye
good bye


gotenks
Avatar of sorriv

ASKER

So I guess my ultimate goal.....looking in a directory (c:\test), opening all .txt files and placing carriage returns every 160 characters is not possible? If this is so maybe I should try a different language? What are your opinions on this?
Why not? You can create the new files (using ofstream) in a different, temporary directory with the same file-name, then delete the files in the original directory and copy back the files from the temporary directory.

Mayank.
Avatar of sorriv

ASKER

Also, I can get the program to run with no errors and it revognizes the .txt file's in the folder, however, it erases the contents as opposed to placing a carriage return every 160 characters.My original code allowed for carriage returns. Is there any way to add this to the program now and get it all to flow?
Did you try the approach that I suggested?
Avatar of sorriv

ASKER

mayankeagle, I did try that and Im not sure why it doesnt work?
Change:

>> strcpy(out_file, file_path);

to:

strcpy ( out_file, <some_other_path> ) ;

And then, repeat the entire process for copying back the files (means that everywhere, the file_path and <some_other_path> will be interchanged).

Mayank.

Avatar of sorriv

ASKER

This is what I have....the program runs and makes a new file "out_...." however it does not copy any data to the file and place the carriage returns. Any suggestions?



#include <io.h> // for _findfirst and _findnext
#include <fstream.h>
#include <iostream.h>
#include <string.h>

char in_file[256];
char out_file[256];

int myFunction(char * in_file, char * out_file) {
char string[161];
ifstream in(in_file);


if(!in)                  
{
     cout<<"File cannot be opened";            
     return -1;
}
ofstream out;
out.open(out_file);        
while(!in.eof())
{
     in.getline(string,161);
     out << string << endl;
}
in.close();
out.close();

return 0;
}

int search_dir(char * file_path) {
struct _finddata_t c_file;
long hFile;

char temp_path[256];
char in_file[256];
char out_file[256];

strcpy(temp_path, file_path);
strcat(temp_path, "*.txt");
// Find first .txt file in current directory
if( (hFile = _findfirst( temp_path, &c_file )) == -1L ) {
   cout << "No *.txt files in current directory!\n";
   return -1;
}
else     {
   // get the file name and create a full path  
   // you can use the "c_file.name" to get the file  
   // name.
   strcpy(in_file, file_path);
   strcat(in_file, c_file.name);

   strcpy(out_file, file_path);
   strcat(out_file, "out_try");
   strcat(out_file, c_file.name);
   
   myFunction(in_file, out_file);
   
   // Find the rest of the .txt files
   while( _findnext( hFile, &c_file ) == 0 ) {
       
     
      strcpy(in_file, file_path);
      strcat(in_file, c_file.name);

      strcpy(out_file, file_path);
      strcat(out_file, c_file.name);
       
      myFunction(in_file, out_file);
     
   }
   _findclose( hFile );
}
return 0;
}

int main() {
char file_name[161];

strcpy(file_name, "c:\\test\\");

search_dir(file_name);
return 0;
}

Avatar of sorriv

ASKER

I now am able to have it modify one single file in the directory....However, it does not go through all of them and do this. Any suggestions....code is below....If I can just get it to go through all the files in the director then I will be good to go.

#include <io.h> // for _findfirst and _findnext
#include <fstream.h>
#include <iostream.h>
#include <string.h>

char in_file[256];
char out_file[256];

int myFunction(char * in_file, char * out_file) {
char string[161];
ifstream in(in_file);


if(!in)                  
{
     cout<<"File cannot be opened";            
     return -1;
}


ofstream out;

out.open(out_file);        
while(!in.eof())
{
     in.getline(string,161);
     out << string << endl;
}
in.close();
out.close();

return 0;
}

int search_dir(char * file_path) {
struct _finddata_t c_file;
long hFile;

char temp_path[256];
char in_file[256];
char out_file[256];


strcpy(temp_path, file_path);
strcat(temp_path, "*.txt");
// Find first .txt file in current directory
if( (hFile = _findfirst( temp_path, &c_file )) == -1L ) {
   cout << "No *.txt files in current directory!\n";
   return -1;
}
else     {
   
   strcpy(in_file, file_path);
   strcat(in_file, c_file.name);

   strcpy(out_file, file_path);
   
   strcat(out_file, c_file.name);
   strcat(out_file, "1");
   myFunction(in_file, out_file);
   
   // Find the rest of the .txt files
   while( _findnext( hFile, &c_file ) == 1 ) {

      myFunction(in_file, out_file);
     
   }
   _findclose( hFile );
}
return 0;
}

int main() {
char file_name[161];

strcpy(file_name, "c:\\test\\");

search_dir(file_name);
return 0;
}
Avatar of sorriv

ASKER

I am now able to get it to manipulate a single file the way I want it to. However, it will not go through all of the text files in the directory....any suggestions?

#include <io.h> // for _findfirst and _findnext
#include <fstream.h>
#include <iostream.h>
#include <string.h>

char in_file[256];
char out_file[256];

int myFunction(char * in_file, char * out_file) {
char string[161];
ifstream in(in_file);


if(!in)                  
{
     cout<<"File cannot be opened";            
     return -1;
}


ofstream out;

out.open(out_file);        
while(!in.eof())
{
     in.getline(string,161);
     out << string << endl;
}
in.close();
out.close();

return 0;
}

int search_dir(char * file_path) {
struct _finddata_t c_file;
long hFile;

char temp_path[256];
char in_file[256];
char out_file[256];


strcpy(temp_path, file_path);
strcat(temp_path, "*.txt");
// Find first .txt file in current directory
if( (hFile = _findfirst( temp_path, &c_file )) == -1L ) {
   cout << "No *.txt files in current directory!\n";
   return -1;
}
else     {
   
   strcpy(in_file, file_path);
   strcat(in_file, c_file.name);

   strcpy(out_file, file_path);
   
   strcat(out_file, c_file.name);
   strcat(out_file, "1");
   myFunction(in_file, out_file);
   
   // Find the rest of the .txt files
   while( _findnext( hFile, &c_file ) == 1 ) {

      myFunction(in_file, out_file);
     
   }
   _findclose( hFile );
}
return 0;
}

int main() {
char file_name[161];

strcpy(file_name, "c:\\test\\");

search_dir(file_name);
return 0;
}
Avatar of sorriv

ASKER

I am now able to get it to manipulate a single file the way I want it to. However, it will not go through all of the text files in the directory....any suggestions?

#include <io.h> // for _findfirst and _findnext
#include <fstream.h>
#include <iostream.h>
#include <string.h>

char in_file[256];
char out_file[256];

int myFunction(char * in_file, char * out_file) {
char string[161];
ifstream in(in_file);


if(!in)                  
{
     cout<<"File cannot be opened";            
     return -1;
}


ofstream out;

out.open(out_file);        
while(!in.eof())
{
     in.getline(string,161);
     out << string << endl;
}
in.close();
out.close();

return 0;
}

int search_dir(char * file_path) {
struct _finddata_t c_file;
long hFile;

char temp_path[256];
char in_file[256];
char out_file[256];


strcpy(temp_path, file_path);
strcat(temp_path, "*.txt");
// Find first .txt file in current directory
if( (hFile = _findfirst( temp_path, &c_file )) == -1L ) {
   cout << "No *.txt files in current directory!\n";
   return -1;
}
else     {
   
   strcpy(in_file, file_path);
   strcat(in_file, c_file.name);

   strcpy(out_file, file_path);
   
   strcat(out_file, c_file.name);
   strcat(out_file, "1");
   myFunction(in_file, out_file);
   
   // Find the rest of the .txt files
   while( _findnext( hFile, &c_file ) == 1 ) {

      myFunction(in_file, out_file);
     
   }
   _findclose( hFile );
}
return 0;
}

int main() {
char file_name[161];

strcpy(file_name, "c:\\test\\");

search_dir(file_name);
return 0;
}
ok, here is more or less the code that will perform the task of copying the output to a temporary file and then re-copy the content of the temporary file back to the original output path/file.

// code start
int myFunction(char * in_file, char * out_file) {
   char string[161];
   ifstream in(in_file);

   if(!in) {
      cout<<"File cannot be opened";            
      return -1;
   }

   ofstream out;
   char temp_out_path[256];

   // set to whatever temporary path that you like
   strcpy(temp_out_path, "e:\\temp_output.txt");

   out.open(temp_out_path);        

   while(!in.eof()) {
      in.getline(string,161);
      out << string << endl;
   }
     
   in.close();
   out.close();

   // now copy back the content to the original output
   // path.
   in.open(temp_out_path);
   if ( !in ) {
      cout << "Temporary file cannot be opened";
      return -1;
   }

   out.open(out_file);
   if ( !out ) {
      cout << "File output cannot be opened";
      return -1;
   }

   while ( !in.eof() ) {
      in.getline(string, 161);
      out << string << endl;
   }

   in.close();
   out.close();

   // finally remove the temp file
   remove(temp_out_path);

   return 0;
}
// code end

that should complete your purposes. good luck.

gotenks
ASKER CERTIFIED SOLUTION
Avatar of gotenks
gotenks

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try this:


#include <io.h>
#include <fstream.h>
#include <iostream.h>
#include <string.h>
#include <stdio.h>

int myFunction ( char * in_file, char * out_file )
{
  char str[161] ;
  ifstream in ( in_file ) ;

  if ( ! in )                  
  {
    cout << "\n File cannot be opened. " ;            
    return -1 ;

  } // end if

  ofstream out ( out_file ) ;        

  while ( ! in.eof () )
  {
    in.getline ( str, 161 ) ;
    out << string << endl ;

  } // end while

  in.close () ;
  out.close () ;

  return 0 ;

} // end of myFunction ()

int search_dir ( char * file_path )
{
  struct _finddata_t c_file ;
  long hFile ;
  char temp_path[256] ;
  char in_file[256] ;
  char out_file[256] ;

  strcpy ( temp_path, file_path ) ;
  strcat ( temp_path, "*.txt" ) ;

  if ( ( hFile = _findfirst ( temp_path, &c_file ) ) == -1L )
  {
    cout << "\n No *.txt files in current directory! " ;
    return -1 ;

  } // end if
 
  else    
  {  
    strcpy ( in_file, file_path ) ;
    strcat ( in_file, c_file.name ) ;
    strcpy ( out_file, file_path ) ;  
    strcat ( out_file, c_file.name ) ;
    strcat ( out_file, "1" ) ;
    myFunction ( in_file, out_file ) ;
   
    while( _findnext ( hFile, &c_file ) == 1 )
    {
      strcpy ( in_file, file_path ) ;
      strcat ( in_file, c_file.name ) ;
      strcpy ( out_file, file_path ) ;  
      strcat ( out_file, c_file.name ) ;
      strcat ( out_file, "1" ) ;
      myFunction ( in_file, out_file ) ;    

    } // end while

    _findclose ( hFile ) ;
 
  } // end else

  return 0 ;

} // end of search_dir ()

int clean_up ( char * file_path )
{
  struct _finddata_t c_file ;
  long hFile ;
  char temp_path[256], in_file[256], temp_name[256] ;

  strcpy ( temp_path, file_path ) ;
  strcat ( temp_path, "*.txt" ) ;

  if ( ( hFile = _findfirst ( temp_path, &c_file ) ) == -1L )
  {
    cout << "\n No *.txt files in current directory! " ;
    return -1 ;

  } // end if
 
  else    
  {  
    strcpy ( in_file, file_path ) ;
    strcat ( in_file, c_file.name ) ;
    unlink ( in_file ) ;
   
    while( _findnext ( hFile, &c_file ) == 1 )
    {
      strcpy ( in_file, file_path ) ;
      strcat ( in_file, c_file.name ) ;
      unlink ( in_file ) ;

    } // end while

    _findclose ( hFile ) ;
 
  } // end else

  strcpy ( temp_path, file_path ) ;
  strcat ( temp_path, "*.txt1" ) ;

  if ( ( hFile = _findfirst ( temp_path, &c_file ) ) == -1L )
  {
    cout << "\n No *.txt1 files in current directory! " ;
    return -1 ;

  } // end if
 
  else    
  {  
    strcpy ( in_file, file_path ) ;
    strcat ( in_file, c_file.name ) ;
    strcpy ( temp_file, file_path ) ;
    strcat ( temp_file, c_file.name ) ;
    temp_file[strlen(temp_file)-1] = '\0' ;
    rename ( in_file, temp_file ) ;
   
    while( _findnext ( hFile, &c_file ) == 1 )
    {
      strcpy ( in_file, file_path ) ;
      strcat ( in_file, c_file.name ) ;
      strcpy ( temp_file, file_path ) ;
      strcat ( temp_file, c_file.name ) ;
      temp_file[strlen(temp_file)-1] = '\0' ;
      rename ( in_file, temp_file ) ;
 
    } // end while

    _findclose ( hFile ) ;
 
  } // end else

  return 0 ;

} // end of clean_up ()

int main ()
{
  char file_path[161] ;

  strcpy ( file_path, "c:\\test\\" ) ;
  search_dir ( file_path ) ;
  clean_up ( file_path ) ;
  return 0 ;

} // end of main ()


Hope that helps!

Mayank.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered: Points to gotenks

Please leave any comments here within the next seven days. Experts: Silence
means you don't care.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

-bcl (bcladd)
EE Cleanup Volunteer
Split between gotenks and mayankeagle. Hope gotenks has no issues with that?
mayankeagle

My only argument with that is my directions were to give the points to the expert who is firstest iwth the mostest.

Having stated my rational I will leave it to the moderator.

-bcl