注册 登录
编程论坛 VC++/MFC

CFileFind FindFile 错误码为2,是什么错误?

lfh001001 发布于 2012-02-29 11:37, 727 次点击
鄙人第一次来编程论坛,庆祝一下,呵呵,只有20可用分啊。崩溃。

先看下代码。
void CCMyMusicPage::OnNMDblclkListMusicLocal(NMHDR *pNMHDR, LRESULT *pResult)
{
    LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<NMITEMACTIVATE*>(pNMHDR);
    // TODO: 在此添加控件通知处理程序代码
    *pResult = 0;

    POSITION pos;
    pos = m_lc_music_local.GetFirstSelectedItemPosition();
    if(pos != NULL)
    {
        int item = m_lc_music_local.GetNextSelectedItem(pos);
        if(item == 0 && !m_b_isRoot)
        {
            CFileFind finder;
            BOOL result = finder.FindFile(m_s_cFilePath);
            int e = GetLastError();
            if(result)
            {
                result = finder.FindNextFile();
                m_s_cFilePath = finder.GetRoot();
                ClearLocalLList();
                InitLocalList(m_s_cFilePath + _T("\\*.*"),FALSE);
                //UpdateData(FALSE);
            }
            finder.Close();
        }
        else{
            CString text = m_lc_music_local.GetItemText(item,0);
            CFileFind finder;
            BOOL result = finder.FindFile(m_s_cFilePath + _T("\\") + text);
            if(result)
            {
                result = finder.FindNextFile();
                if(finder.IsDirectory())
                {
                    ClearLocalLList();
                    InitLocalList(m_s_cFilePath + _T("\\") + text + _T("\\*.*"),FALSE);
                }
            }
            finder.Close();
        }
    }
}

做一个文件列表。上面的函数是响应CListCtrl的双击响应事件。列表中的第一行显示"上一页",所以在双击第一项时,列表显示当前目录的父目录。运行时在第一次双击"上一页"时正常,但是再次双击时
        BOOL result = finder.FindFile(m_s_cFilePath);   结果result = 0;获取错误码
    int e = GetLastError();  得到e = 2;


请各位大侠帮忙看看,这是什么错误啊?谢谢了。
6 回复
#2
lfh0010012012-02-29 11:39
对了,使用vs2008
#3
yuccn2012-02-29 12:36
系统找不到指定的文件。

确认你的文件存在,或者确认你读的文件路径正确。

调试下就知道了
#4
lfh0010012012-02-29 12:53
文件肯定是存在的。
#5
lfh0010012012-02-29 13:41
测试的时候,我把目录系统建了好几层。发现只要连续连词双击上一层就不行
#6
yuccn2012-02-29 13:49
错误代码2 说明没有找到你的文件,如果你确定文件一定正确,那么你确认下m_s_cFilePath 是否就是你要打开文件的路径,在            BOOL result = finder.FindFile(m_s_cFilePath);前面 用::MessageBox(NULL, m_s_cFilePath,NULL, NULL);打出来看看啊
#7
lfh0010012012-02-29 14:07
嗯,谢谢,我知道错误了。崩溃,m_s_cFilePath = finder.GetRoot();  getRoot函数的返回值是以"\\"做结尾的。搞了半天还是需要通过解析字符串来获得已知目录的父目录。VC也太死板了吧。
1