在目录中搜索文件

Search File in a directory

本文关键字:搜索 文件      更新时间:2023-10-16

如何在目录或文件夹中查找特定文件?

我刚刚做了一个函数,试图通过目录路径和文件进行搜索

BOOL CCalibrTreeView :: SearchFile(const CString &directory,const CString &filename)
{
    CFileFind finder;
}

我只想如果文件在目录中,那么return true就是return false

如果需要查找特定文件,可以使用

CString strPath =_T("C:\abc.txt");
if(PathFileExists(strPath)) // pass full path
{
 //file exists
}
else
{
 //file not exists
}

若文件存在,它将返回true,否则将返回false。

PathFileExists函数
确定文件系统对象(如文件或文件夹)的路径是否有效。