MFC获取指定文件夹文件目录

MFC获取指定文件夹文件目录,第1张

在MFC中,使用CFileFind类,可以枚举一行掘掘个目录下的所有文件子目录

示例:

void ListFolder(const CString & sPath)

{

    CFileFind ff   

    BOOL bFound = 档核ff.FindFile(sPath + "\\*.*")

    while(bFound)

    {

        bFound = ff.FindNextFile()

        if(ff.IsDirectory())  //是目录

        {

            if(!ff.IsDots()) 散裂//不是本级目录或父目录(.和..)

                ListFolder(ff.GetFilePath()) //递归子目录

        }

        else

        {

            AfxMessageBox("文件:" + ff.GetFilePath())

        }

    }

    ff.Close()

}

void CXXXDlg::SearchFiles(CString strMusicFolder)

{

    CFileFind ff

    

    strMusicFolder += _T("\\")

    

 局扒喊   strMusicFolder += _T("桐野*.*")

    BOOL res = ff.FindFile(strMusicFolder)

    此世while (res)

    {

        res = ff.FindNextFile()

        if (!ff.IsDirectory() && !ff.IsDots())

        {

            afxMessageBox(ff.GetFilePath())

        }

    }

    ff.Close()

}

int i=0

CString strPath[10]

CFileFind ff

BOOL ret = ff.FindFile("d:\\temp\\*.DAT")

while(ret)

{

ret = ff.FindNextFile()

strPath[i++] = ff.GetFileName()

}

ff.Close()


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/12292348.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-24
下一篇 2023-05-24

发表评论

登录后才能评论

评论列表(0条)

保存