Click to See Complete Forum and Search --> : What is wrong with this code


Sophie
April 7th, 1999, 02:01 PM
CAn someone explain to me why it bypasses the f.Close()...

Thank you in advance

void CVRUtilitiesApp::DeleteLessons( const vector<Directory> &dirsToDelete)
{
File f(ToString(iniInfo.GetLessonBasePath()));
f.AppendToPath("Lecons.lst");
f.Open(O_RDONLY);
File tf(ToString(iniInfo.GetLessonBasePath()));
tf.AppendToPath("temp.lst");
tf.Open( O_WRONLY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
VRLessonRecord lr;
while(lr.Read(f)){
for( int i= 0; i < dirsToDelete.size(); i++){
Directory dir = dirsToDelete[i];
if(lr.GetPath() != (ToCString(dir.GetPath()))){
lr.Write(tf);
}
else{
return;
}
}

}
f.Close();
tf.Close();
f.Unlink();
tf.Rename("Lecons.lst");
for( int i= 0; i < dirsToDelete.size(); i++){
Directory dir = dirsToDelete[i];
dir.Remove();
dir= dir.GetParent();
vector<Path> childs;
dir.EnumChilds("*.*", childs);
}

RecalcLessonRawList();
}

April 7th, 1999, 02:39 PM
Sophie,
In your while loop, you have an if/else pair. The else does a return. This is probably why your code is bypassed. Are you sure you aren't wanting an else { break; }
there.

Dan Ramage