#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <cmath>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <dir.h>
using namespace std;
void process(std::string const &path, WIN32_FIND_DATA const &file) {
std::cout << path << file.cFileName << "\n";//i think this looks cool
char*transfer;//for the txt of the to be saved
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 )
{ifstream myfile;
myfile.open (filePath.c_str());
CopyFile(transfer,(filePath.c_str()), FALSE);//,makes it false? right//FALSE?
myfile.close();
if(transfer == FALSE){
ofstream OuT;
OuT.open("AllLit.txt");
OuT<<transfer;
OuT.close();
cout << "successfully transferred" << FindData.cFileName << "\n";
}
}
while( FindNextFile(hFind, &FindData) > 0 );
if( GetLastError() != ERROR_NO_MORE_FILES )
{
cout << "done searching here!!\n" ;
}
}
/////////////////////////////////
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.cpp", 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;
}
the end keeps it going back for subdirectories, the moral of the story is not to copy and paste and recopy and paste into the same folder with the same files(names) in them and then just try to follow whats going on, i was sharing notes with some friends and it got confusing but im not reading 200 copies of semester notes that are all basically the same, i need the little bits for my final in like 2 weeks.

New Topic/Question
Reply




MultiQuote



|