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 am I doing wrong

    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


  2. #2
    Join Date
    Apr 1999
    Location
    CA, USA
    Posts
    78

    Re: What am I doing wrong

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

    }



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