在指定路径下寻找文件
如题,在指定路径下寻找某个文件,文件名已知,请问有这样的函数吗?
[解决办法]
把这个目录中的所有文件名字等到,或得到一个匹配一个,就可以了
void CReadDlg::FileBrowse(CString strDir)
{
CFileFind ff;
CString szDir = strDir;
CString strPath,strName;
if(szDir.Right(1) != "\\ ")
szDir += "\\ ";
szDir += "*.* ";
BOOL res = ff.FindFile(szDir);
while( res )
{
res = ff.FindNextFile();
if(ff.IsDirectory() && !ff.IsDots())//找到目录
{
m_strfolderpath[m_ncountfolder] = ff.GetFilePath();
m_ncountfolder++;
FileBrowse(m_strfolderpath[m_ncountfolder-1]);
}
if(!ff.IsDirectory() && !ff.IsDots())
{
//strName = ff.GetFileName();
m_strfpath[m_ncout] = ff.GetFilePath();
m_ncout++;
}
}
ff.Close();
}
然后你就自己写一下匹配程序吧,很简单的几句话
[解决办法]
int file_exists(char *filename)
{
return (access(filename, 0) == 0);
}
[解决办法]
int file_exists(char *filename)
{
return (access(filename, 0) == 0);
}
----------------------------------
楼上正解.