#include <stdio.h>
#include <windows.h>

//#define FILE_NAME  "Target.exe"
bool FindWantedFile(char* lpPath);
//void HandleIt(char* lpPath);
int dFound =0;
int fFound =0;

int main()
{
  FindWantedFile("C:\\HNC\\");

printf("\n\n");
printf("찾은 파일:%d \t디렉토리:%d\n", fFound, dFound);

  return 0;
}

bool FindWantedFile(char* lpPath)
{
  HANDLE hSearch;
  WIN32_FIND_DATA ffd;

  SetCurrentDirectory(lpPath);

/*
  hSearch=FindFirstFile(FILE_NAME, &ffd);

  if (hSearch != INVALID_HANDLE_VALUE) {
       HandleIt(lpPath);
       CloseHandle(hSearch);
       return TRUE;
  }
 
  CloseHandle(hSearch);
*/


  hSearch=FindFirstFile("*", &ffd);

  if (hSearch == INVALID_HANDLE_VALUE)
       return FALSE;

  do {
char szPath[MAX_PATH]; // 디렉토리 + 파일명
/////////////////////////////////////////////////////////////////
// 얻어온 파일(혹은 디렉토리)의
// 속성이 디렉토리 인경우
       if (ffd.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY) {

// .이거나 ..이면 PASS~~
           if (strcmp(ffd.cFileName, ".") && strcmp(ffd.cFileName, "..")) {

               wsprintf(szPath, "%s\\%s", lpPath, ffd.cFileName);
printf("D%5d)%s\n", ++dFound, szPath);
              
// 진짜 디렉토리인경우..
// 하위 디렉토리로 들어간다..
if (FindWantedFile(szPath)) {
                   CloseHandle(hSearch);
                   return TRUE;
               }
           }
       }
/////////////////////////////////////////////////////////////////
// 얻어온 파일(혹은 디렉토리)의
// 속성이 파일 인경우
else {
wsprintf(szPath, "%s\\%s", lpPath, ffd.cFileName);
printf("F%5d)%s\n", ++fFound, szPath);
}

//static int a=0;
//printf("%d] %s\\%s\n", ++a, lpPath, ffd.cFileName);
  } while (FindNextFile(hSearch, &ffd));

  FindClose(hSearch);

  return FALSE;
}


/*
void HandleIt(char* lpPath)
{
  // Handle It
}*/


Posted by 장안동베짱e :