CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 1999
    Posts
    121

    What is wrong with this code

    CAn someone explain to me why it bypasses the f.Close()...

    Thank you in advance

    void CVRUtilitiesApp:eleteLessons( 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();
    }


  2. #2
    Guest

    Re: What is wrong with this code

    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured