Windows Server 2003

Hi all.

I have written a program (included at the bottom of post) designed to compare the contents of one folder against another. It works fine on my computer and compiles and run. (windows 7).

When I take the .exe to my father's windows 2003 server, I encounter some strange behaviour, namely that it will copy file 00-00-000.jpg (which does exist on master/) correctly but will then also copy 00-00-001.jpg (this file doesn't exist on master/). This causes the program to be caught in an infinite loop.

Also worth mentioning is that log.txt does not get created, seemingly implying something going wrong with fstream?

I am pressed for time - I plan on spending all of tomorrow working on this and have a few ideas in my head which will hopefully fix my program, but after Friday I won't have access to the machine on which the program needs to be run and the project will have to be put on hiatus.

Knowing this, my question is:
Are there any well known incompatibilities between windows 7 and server 2003, or is there anything in my code that would cause this malfunction that you can see?

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;
}


Thanks - Dan
Last edited on
You can copy a file with CopyFile().

You can't call delete on dump, slave and master as they're variables created on the stack.

You traverse a directories content with FindFristFile()/FindNextFile()/FindClose().

Topic archived. No new replies allowed.