finding and copying a txt file and making a new file with the copy

  • (2 Pages)
  • +
  • 1
  • 2

28 Replies - 2288 Views - Last Post: 12 October 2012 - 08:35 PM Rate Topic: -----

#16 psilocybin420  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 19-September 12

Re: finding and copying a txt file and making a new file with the copy

Posted 10 October 2012 - 06:40 AM

that did help a bit, but instead of the text its giving me hex i believe, i tried using the char transfer, it worked then, but crashed after 3 file transfers, this way found and transferred more of the files, but not in english
        string filePath = path + FindData.cFileName;
	        ifstream in( filePath.c_str() );
	        if( in )
	        {
	            fstream myfile;
	            myfile.open (filePath.c_str());//, ios::out | ios::app
	 //CopyFile(filePath.c_str(),transfer,true);
	           // Copyfile((filePath.c_str()),"AllLITTs.txt", TRUE);//,makes it false? right//FALSE?
	           
fstream OuT;
               OuT.open("AllLit.txt", ios::out |ios::app);
                               OuT<<myfile;//transfer
	                OuT.close();
	                 myfile.close();
	                cout << "successfully transferred"  << FindData.cFileName << "\n";


im gunna mess with it some more when i get out of class, if you see anything thats uproariously wrong with this or know how to do it correctly, leave a comment. you guys rock thanks for the help so far!
Was This Post Helpful? 0
  • +
  • -

#17 psilocybin420  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 19-September 12

Re: finding and copying a txt file and making a new file with the copy

Posted 10 October 2012 - 06:56 AM

0x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d80x22f8d8


^^^ thats whats being appended to alllit.txt, but @ least
it is appending nd not crashihng!
Was This Post Helpful? 0
  • +
  • -

#18 jimblumberg  Icon User is online

  • member icon


Reputation: 4278
  • View blog
  • Posts: 13,439
  • Joined: 25-December 09

Re: finding and copying a txt file and making a new file with the copy

Posted 10 October 2012 - 07:05 AM

That looks like it might be an address of something written several times. Probably from this line:
                OuT<<myfile;

The variable myfile is a stream, you can't output a stream.

Jim
Was This Post Helpful? 0
  • +
  • -

#19 psilocybin420  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 19-September 12

Re: finding and copying a txt file and making a new file with the copy

Posted 10 October 2012 - 07:18 AM

yea but when i do OuT<<transfer it crashes as soon as it finds the file being searched, and myfile doesn't work either it just makes that hex crap
should i try string transfer?
Was This Post Helpful? 0
  • +
  • -

#20 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3662
  • View blog
  • Posts: 11,472
  • Joined: 05-May 12

Re: finding and copying a txt file and making a new file with the copy

Posted 10 October 2012 - 07:37 AM

Show your new code that uses transfer. From what I recall from the old code, you were using transfer as a uninitialized pointer.
Was This Post Helpful? 0
  • +
  • -

#21 jimblumberg  Icon User is online

  • member icon


Reputation: 4278
  • View blog
  • Posts: 13,439
  • Joined: 25-December 09

Re: finding and copying a txt file and making a new file with the copy

Posted 10 October 2012 - 07:38 AM

If you are trying to "transfer" information from the myfile stream to the OuT stream you must first read the data contained in your input file before you can write this information to the output file.

Also you need to test that the files open correctly before you try to either read or write to these files. Be aware that the fstream class requires that the files exist when using the default open modes. If the file is not present the open will fail.

Unless you need to actually access the files for both input and output that you use the ifstream class for input, and the ofstream class for output.

Also please post your entire current program. Don't try to mix the Windows API file calls with the C++ stream classes.

Jim
Was This Post Helpful? 0
  • +
  • -

#22 psilocybin420  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 19-September 12

Re: finding and copying a txt file and making a new file with the copy

Posted 10 October 2012 - 02:27 PM

#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <cmath>
#include <queue>
#include        <stdio.h>
#include        <stdlib.h>
#include        <dir.h>
#include <windows.h>
const HANDLE HNULL = INVALID_HANDLE_VALUE;
const int A_DIR = FILE_ATTRIBUTE_DIRECTORY;
using namespace std;
void process(std::string const &path, WIN32_FIND_DATA const &file)//,int argc, char *argv[]
	{
	    std::cout << path << file.cFileName << "\n";//i think this looks cool
	    const char*transfer;//for the txt of the to be saved
	    string name;
	    string searchPattern = "*alllit.txt";// one of the filenames i need to organize
   string fullSearchPath = path + searchPattern;
	    WIN32_FIND_DATA FindData;
	    HANDLE hFind;

	    hFind = FindFirstFile( fullSearchPath.c_str(), &FindData );

	    if( hFind == INVALID_HANDLE_VALUE )
	    {
	        cout<<"Still searching for LitNotes. \n";
	    }

	    do
	    {
	                string filePath = path + FindData.cFileName;
	        ifstream in( filePath.c_str() );
	        if( in )
	        {
	            fstream myfile;
	            myfile.open (filePath.c_str());//, ios::out | ios::app
	 //CopyFile(filePath.c_str(),transfer,true);
	           // Copyfile((filePath.c_str()),"AllLITTs.txt", TRUE);//,makes it false? right//FALSE?

fstream OuT;
               OuT.open("AllLit.txt", ios::out |ios::app);
                               OuT<<transfer;//transfer
	                OuT.close();
	                 myfile.close();
	                cout << "successfully transferred"  << FindData.cFileName << "\n";

	        }
	    }
	        while( FindNextFile(hFind, &FindData) > 0 );

	        if( GetLastError() != ERROR_NO_MORE_FILES )
	        {
	            cout << "done searching here!!\n" ;
	        }
	    }
	          /*  if(transfer == FALSE)
43	            {
44
49	            }*/
void find_file(std::string const &folder_name, std::string const &fmask) {
    HANDLE finder;          // for FindFirstFile
	    WIN32_FIND_DATA file;   // data about current file.
    std::priority_queue<std::string, std::vector<std::string>,
                       std::greater<std::string> > dirs;
	    dirs.push(folder_name); // start with passed directory

    do {
	        std::string path = dirs.top();// retrieve directory to search
        dirs.pop();

        if (path[path.size()-1] != '\\')  // normalize the name.
            path += "\\";

        std::string mask = path + fmask;    // create mask for searching

        // traverse a directory. Search for sub-dirs separately, because we
	        // don't want a mask to apply to directory names. "*.txt" should find
        // "a\b.txt", even though "a" doesn't match "*.txt".
       //
	        // First search for files:
        if (HNULL==(finder=FindFirstFile(mask.c_str(), &file)))
           continue;

        do {
	            if (!(file.dwFileAttributes & A_DIR))
	                process(path, file);
	        } while (FindNextFile(finder, &file));

        FindClose(finder);

        // Then search for subdirectories:
        if (HNULL==(finder=FindFirstFile((path + "*").c_str(), &file)))
	            continue;
	        do {
	            if ((file.dwFileAttributes & A_DIR) && (file.cFileName[0] != '.'))
	                dirs.push(path + file.cFileName);
	        } while (FindNextFile(finder, &file));
	        FindClose(finder);
	    } while (!dirs.empty());
	}
	int main(int argc, char **argv) {
	    if (argc > 2)
	        find_file(argv[1], argv[2]);
	    else
	        find_file("C:\\", "*");

	    return 0;
	}


that is as far as i have gotten, if i change it to myfile you get that annoying hex such. i really do wish what you guys were talking about, i tried myfile.read(filePath.c_str()); that didnt work, i feel like i dont know how to operate this correctly.
Was This Post Helpful? 0
  • +
  • -

#23 psilocybin420  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 19-September 12

Re: finding and copying a txt file and making a new file with the copy

Posted 10 October 2012 - 03:02 PM

i tried some of what you said, it runs, but now i just get non hex random such like this
X8p88888888(8@8X8p888`8
theres my running code:
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <cmath>
#include <queue>
#include        <stdio.h>
#include        <stdlib.h>
#include        <dir.h>
#include <windows.h>
const HANDLE HNULL = INVALID_HANDLE_VALUE;
const int A_DIR = FILE_ATTRIBUTE_DIRECTORY;
using namespace std;
void process(std::string const &path, WIN32_FIND_DATA const &file)//,int argc, char *argv[]
	{
	    std::cout << path << file.cFileName << "\n";//i think this looks cool
	    const char*transfer;//for the txt of the to be saved
	    string name;
	    string searchPattern = "*.txt";// one of the filenames i need to organize
   string fullSearchPath = path + searchPattern;
	    WIN32_FIND_DATA FindData;
	    HANDLE hFind;

	    hFind = FindFirstFile( fullSearchPath.c_str(), &FindData );

	    if( hFind == INVALID_HANDLE_VALUE )
	    {
	        cout<<"Still searching for LitNotes. \n";
	    }

	    do
	    {
	                string filePath = path + FindData.cFileName;
	        ifstream in( filePath.c_str() );
	        if( in )
	        {

fstream OuT;
  OuT.open("AllLit.txt", ios::out |ios::app);
	            fstream myfile;
	            myfile.open (filePath.c_str(), ios::out | ios::app);//, ios::out | ios::app
	             // get length of file:
  OuT.seekg (0, ios::end);
  length = OuT.tellg();
  OuT.seekg (0, ios::beg);

  // allocate memory:
  buffer = new char [length];

  // read data as a block:
  OuT.read (buffer,length);
  OuT.close();

  cout.write (buffer,length);


	 //CopyFile(filePath.c_str(),transfer,true);
	           // Copyfile((filePath.c_str()),"AllLITTs.txt", TRUE);//,makes it false? right//FALSE?




                               OuT<<buffer;//transfer
	                OuT.close();
	               // delete[] buffer;
	                 myfile.close();
	                cout << "successfully transferred"  << FindData.cFileName << "\n";

	        }
	    }
	        while( FindNextFile(hFind, &FindData) > 0 );

	        if( GetLastError() != ERROR_NO_MORE_FILES )
	        {
	            cout << "done searching here!!\n" ;
	        }
	    }
	          /*  if(transfer == FALSE)
43	            {
44
49	            }*/
void find_file(std::string const &folder_name, std::string const &fmask) {
    HANDLE finder;          // for FindFirstFile
	    WIN32_FIND_DATA file;   // data about current file.
    std::priority_queue<std::string, std::vector<std::string>,
                       std::greater<std::string> > dirs;
	    dirs.push(folder_name); // start with passed directory

    do {
	        std::string path = dirs.top();// retrieve directory to search
        dirs.pop();

        if (path[path.size()-1] != '\\')  // normalize the name.
            path += "\\";

        std::string mask = path + fmask;    // create mask for searching

        // traverse a directory. Search for sub-dirs separately, because we
	        // don't want a mask to apply to directory names. "*.txt" should find
        // "a\b.txt", even though "a" doesn't match "*.txt".
       //
	        // First search for files:
        if (HNULL==(finder=FindFirstFile(mask.c_str(), &file)))
           continue;

        do {
	            if (!(file.dwFileAttributes & A_DIR))
	                process(path, file);
	        } while (FindNextFile(finder, &file));

        FindClose(finder);

        // Then search for subdirectories:
        if (HNULL==(finder=FindFirstFile((path + "*").c_str(), &file)))
	            continue;
	        do {
	            if ((file.dwFileAttributes & A_DIR) && (file.cFileName[0] != '.'))
	                dirs.push(path + file.cFileName);
	        } while (FindNextFile(finder, &file));
	        FindClose(finder);
	    } while (!dirs.empty());
	}
	int main(int argc, char **argv) {
	    if (argc > 2)
	        find_file(argv[1], argv[2]);
	    else
	        find_file("C:\\", "*");

	    return 0;
	}


it also still crashes at the end but it does read all of my text files and produce output! i think were coming to the finish of making a full text reader/ appender! does anyone know how to change the garbely gook into words?
Was This Post Helpful? 0
  • +
  • -

#24 jimblumberg  Icon User is online

  • member icon


Reputation: 4278
  • View blog
  • Posts: 13,439
  • Joined: 25-December 09

Re: finding and copying a txt file and making a new file with the copy

Posted 10 October 2012 - 03:10 PM

I really think you don't really understand basic C++ file input and output and trying to add the complexities of the Windows API to the mix is really confusing you. If you must use the Windows API calls I recommend you stick with the API for all the file handling. This means sticking with C-strings instead of C++ strings, the Windows API doesn't understand C++ it is a C API.

If you still think you must mix C and C++ you should try to separate the Windows API calls from your C++ functions as much as possible. Use functions that deal only in the Windows API, and functions that take this C information and use it.

Also you probably should review how to use C++ streams for input and output.

Jim

This post has been edited by jimblumberg: 10 October 2012 - 03:10 PM

Was This Post Helpful? 0
  • +
  • -

#25 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3662
  • View blog
  • Posts: 11,472
  • Joined: 05-May 12

Re: finding and copying a txt file and making a new file with the copy

Posted 10 October 2012 - 03:35 PM

Why are you trying to read out of your out file? (lines 39-54) You should read out of your in file, and write out to your outfile the number of bytes you read it. Additionally, you need to keep on reading and writing until you exhaust all your input.

I highly recommend that you set aside this program for a little while and tackle a small program first whose only objectives are:
- open the first command line parameter as an input file
- open the second command line parameter as an output file
- read all the contents of the input file and append it to the output file.

That's it. Don't confuse yourself with doing the Windows directory recursion. Once you figure out how to do that, you can apply what you learned back to this program.
Was This Post Helpful? 0
  • +
  • -

#26 psilocybin420  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 19-September 12

Re: finding and copying a txt file and making a new file with the copy

Posted 10 October 2012 - 05:45 PM

C:\LarsonsMath\   C:\LarsonsMath\  
Legible words are coming out!! and note this is the folder the file is in!!!(i made a text file for refrence) although i have been kinda just rewriting my notes and deleting entries just to get my homework started. i am going to write a smaller program to get this all running correctly and to better understand the situation. but i am only trying this because i am taking a programming class and my teacher will give me extra credit for robust programs, i got the c++ bug now lol.


#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <cmath>
#include <queue>
#include        <stdio.h>
#include        <stdlib.h>
#include        <dir.h>
#include <windows.h>
const HANDLE HNULL = INVALID_HANDLE_VALUE;
const int A_DIR = FILE_ATTRIBUTE_DIRECTORY;
using namespace std;
void process(std::string const &path, WIN32_FIND_DATA const &file)//,int argc, char *argv[]
	{
	    std::cout << path << file.cFileName << "\n";//i think this looks cool
	    char*transfer;//for the txt of the to be saved//const 
	    string name;
	    string searchPattern = "*ddd.txt";// one of the filenames i need to organize
   string fullSearchPath = path + searchPattern;
	    WIN32_FIND_DATA FindData;
	    HANDLE hFind;

	    hFind = FindFirstFile( fullSearchPath.c_str(), &FindData );

	    if( hFind == INVALID_HANDLE_VALUE )
	    {
	        cout<<"Still searching for LitNotes. \n";
	    }

	    do
	    {
	                string filePath = path + FindData.cFileName;
	        ifstream in( filePath.c_str() );
	        if( in )
	        {int length;

ofstream OuT;
  OuT.open("AllLit.txt", ios::out |ios::app);
	            fstream myfile;
	            myfile.open (filePath.c_str(), ios::out | ios::app);//, ios::out | ios::app
	             // get length of file:
  myfile.seekg (0, ios::end);
  length = myfile.tellg();
  myfile.seekg (0, ios::beg);

  // allocate memory:
  transfer = new char [length];

  // read data as a block:
  myfile.read (transfer,length);

  //cout.write (transfer,length);
//Out.read (transfer,length);
OuT.write(transfer, length);

	 //CopyFile(filePath.c_str(),transfer,true);
	           // Copyfile((filePath.c_str()),"AllLITTs.txt", TRUE);//,makes it false? right//FALSE?




                               //OuT<<transfer;//transfer
	                OuT.close();
	                delete[] transfer;
	                 myfile.close();
	                cout << "successfully transferred"  << FindData.cFileName << "\n";

	        }
	    }
	        while( FindNextFile(hFind, &FindData) > 0 );

	        if( GetLastError() != ERROR_NO_MORE_FILES )
	        {
	            cout << "done searching here!!\n" ;
	        }
	    }
	          /*  if(transfer == FALSE)
43	            {
44
49	            }*/
void find_file(std::string const &folder_name, std::string const &fmask) {
    HANDLE finder;          // for FindFirstFile
	    WIN32_FIND_DATA file;   // data about current file.
    std::priority_queue<std::string, std::vector<std::string>,
                       std::greater<std::string> > dirs;
	    dirs.push(folder_name); // start with passed directory

    do {
	        std::string path = dirs.top();// retrieve directory to search
        dirs.pop();

        if (path[path.size()-1] != '\\')  // normalize the name.
            path += "\\";

        std::string mask = path + fmask;    // create mask for searching

        // traverse a directory. Search for sub-dirs separately, because we
	        // don't want a mask to apply to directory names. "*.txt" should find
        // "a\b.txt", even though "a" doesn't match "*.txt".
       //
	        // First search for files:
        if (HNULL==(finder=FindFirstFile(mask.c_str(), &file)))
           continue;

        do {
	            if (!(file.dwFileAttributes & A_DIR))
	                process(path, file);
	        } while (FindNextFile(finder, &file));

        FindClose(finder);

        // Then search for subdirectories:
        if (HNULL==(finder=FindFirstFile((path + "*").c_str(), &file)))
	            continue;
	        do {
	            if ((file.dwFileAttributes & A_DIR) && (file.cFileName[0] != '.'))
	                dirs.push(path + file.cFileName);
	        } while (FindNextFile(finder, &file));
	        FindClose(finder);
	    } while (!dirs.empty());
	}
	int main(int argc, char **argv) {
	    if (argc > 2)
	        find_file(argv[1], argv[2]);
	    else
	        find_file("C:\\", "*");

	    return 0;
	}


that should tell you the directory *ddd.txt is in, if you change the ddd to *lit.txt it works the same, it tells you the directory, and puts in thoose ascii characters.
Was This Post Helpful? 0
  • +
  • -

#27 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3662
  • View blog
  • Posts: 11,472
  • Joined: 05-May 12

Re: finding and copying a txt file and making a new file with the copy

Posted 11 October 2012 - 01:02 AM

Why do you have both ifstream in, and fstream myfile?

Why are you opening myfile for output using ios::out, but doing reads from it?

Why are you allocating a buffer as big as the file you are reading, and then reading everything into memory? What happens if the file is 30GB?

This post has been edited by Skydiver: 11 October 2012 - 01:04 AM

Was This Post Helpful? 1
  • +
  • -

#28 psilocybin420  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 19-September 12

Re: finding and copying a txt file and making a new file with the copy

Posted 11 October 2012 - 04:11 PM

omg it worked! it actually worked! ill post the code later!
Was This Post Helpful? 0
  • +
  • -

#29 psilocybin420  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 19-September 12

Re: finding and copying a txt file and making a new file with the copy

Posted 12 October 2012 - 08:35 PM

	#include <cstdlib>
	#include <iostream>
	#include <fstream>
    	#include <sstream>
#include <cmath>
#include <queue>
#include        <stdio.h>
#include        <stdlib.h>
#include        <dir.h>
	#include <windows.h>
	const HANDLE HNULL = INVALID_HANDLE_VALUE;
	const int A_DIR = FILE_ATTRIBUTE_DIRECTORY;
	using namespace std;
	void process(std::string const &path, WIN32_FIND_DATA const &file)//,int argc, char *argv[]
	    {
	        std::cout << path << file.cFileName << "\n";//i think this looks cool
	        char*transfer;//for the txt of the to be saved//const
	        string name;
	        string searchPattern = "*LitNotes.txt";// one of the filenames i need to organize
	   string fullSearchPath = path + searchPattern;
	        WIN32_FIND_DATA FindData;
	        HANDLE hFind;
	 
	        hFind = FindFirstFile( fullSearchPath.c_str(), &FindData );
	 
	        if( hFind == INVALID_HANDLE_VALUE )
	        {
	            cout<<"Still searching for LitNotes. \n";
	        }
	 
	        do
	        {
	                    string filePath = path + FindData.cFileName;
	            ifstream in( filePath.c_str() );
	            if( in )
	            {int length;
	 
	ofstream OuT;
	  OuT.open("AllLit.txt", ios::out |ios::app);
	               // fstream myfile;
	                //myfile.open (filePath.c_str(), ios::out | ios::app);//, ios::out | ios::app
	                 // get length of file:
	  in.seekg (0, ios::end);
	  length = in.tellg();
	 in.seekg (0, ios::beg);
	 
	  // allocate memory:
  transfer = new char [length];
	 	  // read data as a block:
	  in.read (transfer,length);
	 
	  //cout.write (transfer,length);
	//Out.read (transfer,length);
	OuT.write(transfer, length);
	 
	     //CopyFile(filePath.c_str(),transfer,true);
	               // Copyfile((filePath.c_str()),"AllLITTs.txt", TRUE);//,makes it false? right//FALSE?
	 
	 
	  
	                               //OuT<<transfer;//transfer
	                    OuT.close();
	                    delete[] transfer;
	                     in.close();
	                    cout << "successfully transferred"  << FindData.cFileName << "\n";
	 
	            }
	        }
	            while( FindNextFile(hFind, &FindData) > 0 );
	 
	            if( GetLastError() != ERROR_NO_MORE_FILES )
	            {
	                cout << "done searching here!!\n" ;
	            }
	        }
	              /*  if(transfer == FALSE)
079	43              {
080	44
081	49              }*/
	void find_file(std::string const &folder_name, std::string const &fmask) {
	    HANDLE finder;          // for FindFirstFile
	        WIN32_FIND_DATA file;   // data about current file.
	    std::priority_queue<std::string, std::vector<std::string>,
	                       std::greater<std::string> > dirs;
	        dirs.push(folder_name); // start with passed directory
	 
	    do {
	            std::string path = dirs.top();// retrieve directory to search
	        dirs.pop();
	 
	        if (path[path.size()-1] != '\\')  // normalize the name.
	            path += "\\";
	 
	        std::string mask = path + fmask;    // create mask for searching
	 
	        // traverse a directory. Search for sub-dirs separately, because we
	            // don't want a mask to apply to directory names. "*.txt" should find
	        // "a\b.txt", even though "a" doesn't match "*.txt".
	       //
	            // First search for files:
	        if (HNULL==(finder=FindFirstFile(mask.c_str(), &file)))
	           continue;
	 
	        do {
	                if (!(file.dwFileAttributes & A_DIR))
	                    process(path, file);
	            } while (FindNextFile(finder, &file));
	 	        FindClose(finder);
	 
	        // Then search for subdirectories:
	        if (HNULL==(finder=FindFirstFile((path + "*").c_str(), &file)))
	                continue;
	            do {
	                if ((file.dwFileAttributes & A_DIR) && (file.cFileName[0] != '.'))
	                    dirs.push(path + file.cFileName);
	            } while (FindNextFile(finder, &file));
	            FindClose(finder);
	        } while (!dirs.empty());
	    }
	    int main(int argc, char **argv) {
	        if (argc > 2)
	            find_file(argv[1], argv[2]);
	        else
	            find_file("C:\\", "*");
	 
	        return 0;
            	    }



that works! just change the search pattern for your own purposes, Thank all of you!, i really appreciate all of what ya did to help me. i learned a bunch compiling this over and over! and thank you for not spoon feeding me.. have a great day and have fun coding!

you dont even know how much this makes me happy!! i looked through the HUGE resulting file and found all of the notes i made, too bad i suck @ this class. either way i got my paper started and its all thanks to yall
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2