Click to See Complete Forum and Search --> : What am I doing wrong


Sophie
April 15th, 1999, 06:50 PM
void CVRUtilitiesApp::CopyLessons( const CString & src, const CString &dst, const vector<Lesson> &lessonToCopy)
{

File f(ToString(iniInfo.GetLessonBasePath()));
f.AppendToPath("Lecons.lst");
f.Open(O_RDONLY);
VRLessonRecord lr;
vector<VRLessonRecord> lrCopy;
while(lr.Read(f)) {
for( int i= 0; i < lessonToCopy.size(); i++){
if(lr.GetName() == lessonToCopy[i].GetLessonName()){
lrCopy.push_back(lr);
break;
}

}

}
f.Close();
for( int k= 0; k < lessonToCopy.size(); k++) {

File tl(ToString(dst));
tl.AppendToPath("Lesons.lst");
tl.Open(O_RDONLY);
tt.AppendToPath("temp.lst");
tt.Open( O_WRONLY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE)
VRLessonRecord lrDest;
while(lrDest.Read(tl)){
if(lrDest.GetName() != lessonToCopy[k].GetLessonName()){
lrDest.Write(tt);
}
}
for(int d=0; d< lrCopy.size(); d++){
if(lrCopy[d].GetName() == lessonToCopy[k].GetLessonName()){
CString path = lrCopy[d].GetPath();
lrDest.SetPath(src,dst,path); *** PROBLEM HERE
lrCopy[d].Write(tt);
break;
}
}
tl.Close();
tt.Close();
tl.Unlink();
tt.Rename(tl);

}


}
void VRLessonRecord::SetPath(const CString &src, const CString &dst, const CString &path )
{
Path newPath = ToString(path);
Path destPath = newPath.CalcMvPath(ToString(src), ToString(dst));
strcpy(PathLecon, destPath);

}

My problem is that I don't write the right path. For example,

src = C:\LAVAC\LECONS
dst = C:\MIKE
path = C:\LAVAC\LECONS\L0000001

after the SetPath function

PathLecon = C:\MIKE\L0000001

But when I try to write it to the temporary file I write the path not the newpath. What am I doing wrong?

Can someone help me!

Thank You

Lynx
April 15th, 1999, 11:35 PM
I guess that there are two things wrong, please look at the comment:
void CVRUtilitiesApp::CopyLessons( const CString & src, const CString &dst, const vector<Lesson> &lessonToCopy)
{

File f(ToString(iniInfo.GetLessonBasePath()));
f.AppendToPath("Lecons.lst");
f.Open(O_RDONLY);
VRLessonRecord lr;
vector<VRLessonRecord> lrCopy;
while(lr.Read(f)) {
for( int i= 0; i < lessonToCopy.size(); i++){
if(lr.GetName() == lessonToCopy.GetLessonName()){ // the lessonToCopy should be lessonToCopy[i]??
lrCopy.push_back(lr);
break;
}

}

}
f.Close();
for( int k= 0; k < lessonToCopy.size(); k++) {

File tl(ToString(dst));
tl.AppendToPath("Lesons.lst");
tl.Open(O_RDONLY);
tt.AppendToPath("temp.lst");
tt.Open( O_WRONLY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE)
VRLessonRecord lrDest;
while(lrDest.Read(tl)){
if(lrDest.GetName() != lessonToCopy[k].GetLessonName()){
lrDest.Write(tt);
}
}
for(int d=0; d< lrCopy.size(); d++){
if(lrCopy[d].GetName() == lessonToCopy[k].GetLessonName()){
CString path = lrCopy[d].GetPath();
lrDest.SetPath(src,dst,path); //*** PROBLEM HERE
lrCopy[d].Write(tt); // should it be lrDest.Write(tt); ???
break;
}
}
tl.Close();
tt.Close();
tl.Unlink();
tt.Rename(tl);

}


}
void VRLessonRecord::SetPath(const CString &src, const CString &dst, const CString &path )
{
Path newPath = ToString(path);
Path destPath = newPath.CalcMvPath(ToString(src), ToString(dst));
strcpy(PathLecon, destPath);

}