1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
/*This program will check the files within a slave folder against a master folder.
It will then make a log of which files were not present in the slave folder and
will copy the missing content into a dump folder*/
#include<iostream>
#include<fstream>
#include<string>
#include<sstream>
#define USE_BINARY_MODE
using namespace std;
int masterProc=0,slaveProc=0,dumpProc=0;
ofstream ofs;
string format2(int i)
{
char j[2];
sprintf(j,"%02i", i);
string p = j;
return(p);
}
string format3(int i)
{
char j[3];
sprintf(j,"%03i", i);
string p = j;
return(p);
}
void copy(string master, string dump)
{
cout<<"Commence copying of "<<master<<endl;
ifstream ifs;
ofstream ofs2;
ifs.open(master.c_str(),ios::binary);
ofs2.open(dump.c_str(),ios::binary);
char c;
while(!ifs.eof())
{
ifs.get(c);
if(ifs.eof())
{
cout<<"Copying of "<<master<<" complete."<<endl;
dumpProc ++;
break;
}
ofs2.put(c);
}
ofs<<dumpProc<<": ["<<master <<" copied to "<<dump<<"]"<<endl;
}
int main()
{
ofs.open("log.txt");
char master[100],slave[100],dump[100];
string l,m,n,masterFile,slaveFile,dumpFile, smaster,sslave,sdump;
cout<<"This program will compare the images present in the master folder "<<endl<<
"e.g. BURNSBRSL against a slave folder e.g. wwwroot/stockimages and send"<<endl<<
" a copy from the master folder to a dump folder of any files missing "
<<endl<<"from the slave folder..."<<endl<<" "<<endl;
cout<<"Please input the full path of the master folder"<<endl;
cin.getline(master,100);
cout<<"Please input the slave folder."<<endl;
cin.getline(slave,100);
cout<<"Please input the dump folder."<<endl;
cin.getline(dump,100);
smaster = master;
sslave = slave;
sdump = dump;
delete(dump);
delete(slave);
delete(master);
for(int i = 0; i<82; i++)
{
string q=format2(i);
cout<<"Current progress: "<<q<<"-XX-XXX"<<endl;
l = format2(i);
for(int j = 0; j<89; j++)
{
m = format2(j);
for(int k = 0; k<1000; k++)
{
ifstream ifs;
ifstream ifs2;
n = format3(k);
masterFile = smaster +l+ "\\" + m + "\\" +l+"-"+m+"-"+n + ".jpg";
slaveFile = sslave +l+ "\\" + m + "\\" + l+"-"+m+"-"+n + ".jpg";
dumpFile = sdump + l+"-"+m+"-"+n + ".jpg";
ifs.open(masterFile.c_str());
if(ifs.is_open())
{
masterProc ++;
ifs2.open(slaveFile.c_str());
if(!ifs2.is_open())
{
copy(masterFile,dumpFile);
}
else
{
slaveProc ++;
}
}
}
}
cout<<masterProc<<" files found so far in master folder."<<endl;
cout<<slaveProc<<" files found so far in slave fodler."<<endl;
cout<<dumpProc<<" files copied so far to dump folder."<<endl;
}
ofs<<masterProc<<" files were found in "<<smaster<<endl;
ofs<<slaveProc<<" files were found in "<<sslave<<endl;
ofs<<dumpProc<<" files were copied to "<<sdump<<endl;
}
|