1 /***************************************************************
 2 函数名称:FindFile
 3 查找指定目录下指定文件
 4 输入:fileName:指定文件名,fileNath:指定查找路径
 5 输出:打印文件路径
 6 ***************************************************************/
 7 int FindFile(string fileName, string filePath)
 8 {
 9     assert(fileName != "" && filePath != "");
10     string exeName = fileName.substr(fileName.find_last_of('.'));
11     string strPath = filePath;
12     string filiterName = "*.*";
13     if ( strPath[strPath.length() - 1] != '\\')
14     {
15         strPath = strPath + "\\";
16     }
17     _finddata_t fileInfo;
18     long handle = _findfirst((strPath + filiterName).c_str(), &fileInfo);
19     if (handle == -1L)
20     {
21         cout<<"Cannot Open The Path!"<<endl;
22         return 0;
23     }
24     do
25     {
26         string path = fileInfo.name;
27         if (fileInfo.attrib & _A_SUBDIR)
28         {
29             if (strcmp(fileInfo.name, ".") != 0 && strcmp(fileInfo.name, "..") != 0)
30             {
31                 FindFile(fileName, strPath + path + "\\");
32             }
33         }
34         else if (fileInfo.attrib & _A_ARCH && path.substr(path.find_last_of('.')) == exeName)
35         {
36             cout<<strPath + fileInfo.name<<endl;
37         }
38     }while (_findnext(handle, &fileInfo) == 0);
39     _findclose(handle);
40     return 0;
41 }