CString tempDir = VideoPath; if(tempDir.Right(1) != "\\")
{
tempDir.Insert(tempDir.GetLength() - 1, "\\");
//tempDir += "\\";
} tempDir += "*.*";
其中VideoPath是CString的全局变量,为什么执行完后,tempDir保持VideoPath原来的值,没有改变,不论执不执行if里面的都一样。

解决方案 »

  1.   

    CString tempDir = "c:\\1";
    if(tempDir.Right(1) != "\\")
    {
    tempDir.Insert(tempDir.GetLength(), "\\");
    //tempDir += "\\";
    }
      

  2.   

    tempDir.Insert(tempDir.GetLength() - 1, "\\");
    这个不应该用Insert吧。应该用tempDir += "\\";
      

  3.   

    当然,用tempDir += "\\";比较普遍些
      

  4.   

    我就是因为tempDir += "\\";不行,才用的现在的,结果一样,不知道为什么
      

  5.   

    不会吧。。要不你把你的工程发给我看看
    [email protected]
      

  6.   

    void CXDReplayerDlg::LoadCoder()
    {
    char *lpStr1 = (LPSTR)(LPCTSTR)VideoPath;

    BOOL te = PathFileExists(lpStr1);
    if (!te)
    {
    char* msg = "指定文件夹不存在.";
    char* title = "错误";
    MessageBox(msg, title, MB_OK | MB_ICONERROR);
    return;
    } CFileFind ff;
    int Dindex = 0;
    CString tempDir = VideoPath; if(tempDir.Right(1) != "\\")
    {
    tempDir.Insert(tempDir.GetLength() - 1, "\\");
    //tempDir += "\\";
    } tempDir += "*.*"; BOOL res = ff.FindFile(tempDir);
    m_COBDevice.Clear();
    while(res)
    {
    res = ff.FindNextFile(); Dindex ++; if(ff.IsDirectory() && !ff.IsDots())
    {
    CString strTitle = ff.GetFileTitle();
    m_COBDevice.InsertString(Dindex, strTitle);
    }
    }
    }
    这是整个函数
    引用的这个
    extern CString VideoPath;
      

  7.   

    lixiaosan(小三): come on
    关注中。
    期待解答。
    顶。
      

  8.   

    CString tempDir = "\\abcde\\sdfsld"; if(tempDir.Right(1) != "\\")
    {
    tempDir += "\\";
    //tempDir.Insert(tempDir.GetLength() - 1, "\\");
    //tempDir += "\\";
    } 这样可以,VC6 SP5 测试通过。
      

  9.   

    调用LoadCoder()时,你看了VideoPath的值是什么了么?
      

  10.   

    但在我的程序中,不行啊
    难道VideoPath有什么问题嘛
      

  11.   

    VideoPath的值没问题,我用debug看了
      

  12.   

    你无非是想判断得到的路径字符串最后是否是"\\",如果没有就加一个"\\",就代码来说
    tempDir += "\\";是应该没有问题的,你设置断点,再试试。
      

  13.   

    看代码看不出啥问题啊。
    郁闷中。
    能不能 VideoPath先加\\*.*,然后再让tempdir等于它呢??
      

  14.   

    实在不行,如果方便就把工程发到[email protected]
      

  15.   

    我写过n编这种代码了。
    这段代码没有问题的。关键是你那个VideoPath;的值对不对??
    加一句判断
    看路径对不对???
    前面
    #include "io.h"
    if(access(VideoPath,0))
    {
    AfxMessageBox("他奶奶的。这个路径不存在了,去哪儿了?????");
    }
      

  16.   

    to sodangerous(机器人)急也没用呀
    向三哥请教一下就行了
    以后我都跟小三混了
    -------------------
    我也是小弟啊。我也想找老大。。呵呵。。^_^。