Copy Code code as follows:
#include <stdio.h>
#include <windows.h>
void FindFile (char*, char*);
int count=0;//Statistics File number
Char fname[32];
#define BUFSIZE 256
int main (int argc,char* argv[])
{
Char Szlogicaldrivestrings[bufsize];
DWORD ilength;
int isub;
printf ("Please enter the filename to search for:");
scanf ("%s", fname);
ZeroMemory (Szlogicaldrivestrings, bufsize);
Ilength = Getlogicaldrivestringsa (BUFSIZE-1, szlogicaldrivestrings);
for (isub=0; isub<ilength; isub+=4)
{
If not a fixed disk drive: local hard drive or mobile hard drive, ignore
if (GetDriveType (szlogicaldrivestrings+isub)!=3)
Continue
FindFile (Szlogicaldrivestrings+isub, "*.*");
}
printf ("Total%d files found ... \ n", count);
scanf ("%*d");
return 0;
}
void FindFile (char* pfilename,char* pfilter)
{
Win32_find_data findfiledate;
HANDLE Hfind;
Char filename[512];
Char lpfilename[512];
Char _lpfilename[512];
int i;
int result;
For (i=0;* (pfilename+i)!= ' "; i++)
filename[i]=* (Pfilename+i);
Filename[i]= ' ";
If the last character is not a ' \ '
if (Filename[strlen (filename) -1]!= ' \ \ ")
strcat (filename, "\ \"); Add ' \ '
strcpy (Lpfilename,filename);
strcat (Lpfilename,pfilter);
Hfind=findfirstfile (lpfilename,&findfiledate);
if (Hfind==invalid_handle_value)
Return
Todo
{
If it is not a directory
if (!) ( Findfiledate.dwfileattributes&file_attribute_directory))
{
If the specified file is found
if (0==strcmp (fname,findfiledate.cfilename))
{
printf ("%s%s\n", filename,findfiledate.cfilename);
count++;
}
}
If it is a directory
Else
{
. and.. Do not output
if (findfiledate.cfilename[0]!= '. ')
{
strcpy (_lpfilename,filename);
strcat (_lpfilename,findfiledate.cfilename);
FindFile (_lpfilename,pfilter); Recursion
}
}
}while (FindNextFile (hfind,&findfiledate));//findnextfile back to true, continue searching
FindClose (hfind);
Return
}
Use the recursive search file, the efficiency is low, use multithreading effect better.