/***************************************************************
函数名称:FindFile
查找指定目录下指定文件
输入:fileName:指定文件名,fileNath:指定查找路径
输出:打印文件路径
***************************************************************/
int FindFile(string fileName, string filePath)
{
assert(fileName != "" && filePath != "");
string exeName = fileName.substr(fileName.find_last_of('.'));
string strPath = filePath;
string filiterName = "*.*";
if ( strPath[strPath.length() - ] != '\\')
{
strPath = strPath + "\\";
}
_finddata_t fileInfo;
long handle = _findfirst((strPath + filiterName).c_str(), &fileInfo);
if (handle == -1L)
{
cout<<"Cannot Open The Path!"<<endl;
return ;
}
do
{
string path = fileInfo.name;
if (fileInfo.attrib & _A_SUBDIR)
{
if (strcmp(fileInfo.name, ".") != && strcmp(fileInfo.name, "..") != )
{
FindFile(fileName, strPath + path + "\\");
}
}
else if (fileInfo.attrib & _A_ARCH && path.substr(path.find_last_of('.')) == exeName)
{
cout<<strPath + fileInfo.name<<endl;
}
}while (_findnext(handle, &fileInfo) == );
_findclose(handle);
return ;
}
04-13 09:53