Directory Depth 구하는 함수 (VC)

DWORD QueryMaximumDepthofSomePath(LPCTSTR lpszPath)
{
 WIN32_FIND_DATA wfs;
 HANDLE hFile = NULL;

 TCHAR FullDirPath[MAX_PATH];
 TCHAR NewDirPath[MAX_PATH];
 ZeroMemory(FullDirPath, sizeof(FullDirPath));
 ZeroMemory(NewDirPath, sizeof(NewDirPath));

 int nCount = 1;      //디렉토리 깊이 (입력받은 lpszPath 부터 카운트 한다.)
 int nTotCount = 0;     //최하위 디렉토리 깊이

 // 폴더가 존재 하는지, 드라이브인지 체크
 if ( PathIsRoot(lpszPath) || _access(lpszPath, 0) == -1 )
 {
  return 0;
 }

 wsprintf(FullDirPath,
    "%s\\*.*",lpszPath);

 // Start scaning the directory
 hFile = FindFirstFile(FullDirPath, &wfs);

 // Check the return handle value
 do
 {
  // Check is the current found file is directory?
  if ((FILE_ATTRIBUTE_DIRECTORY & wfs.dwFileAttributes))
  {
   if( lstrcmp(wfs.cFileName,".") == 0 ){}
   else if( lstrcmp(wfs.cFileName,"..") == 0 ){}
   else
   {
    wsprintf(NewDirPath, "%s\\%s", lpszPath, wfs.cFileName);
    subDepthDirecty(NewDirPath, &nCount, &nTotCount);
   }
  }
 
  // Scan the next match item in the directory
  if (!FindNextFile(hFile, &wfs))
  {
   if (ERROR_NO_MORE_FILES == GetLastError()) {break;}
  }

 } while (NULL != hFile || INVALID_HANDLE_VALUE != hFile);


 if (NULL != hFile)
 {
  FindClose(hFile);
 }
 hFile = NULL;

 return nTotCount;
}

 

 

 

void subDepthDirecty(LPCTSTR szPath, int* pCount, int* pTotCount)
{
 HANDLE hFile;
 WIN32_FIND_DATA  fData;
 TCHAR FullDirPath[MAX_PATH];
 TCHAR NewDirPath[MAX_PATH];
 BOOL bResult = TRUE;

 (*pCount)++;
 wsprintf(FullDirPath, "%s\\*.*", szPath);
 hFile = FindFirstFile(FullDirPath, &fData);

 while(bResult)
 {
  if ((FILE_ATTRIBUTE_DIRECTORY & fData.dwFileAttributes))
  {
   if( lstrcmp(fData.cFileName,".") == 0 ){}
   else if( lstrcmp(fData.cFileName,"..") == 0 ){}
   else
   {
    wsprintf(NewDirPath, "%s\\%s", szPath, fData.cFileName);
    subDepthDirecty(NewDirPath, &(*pCount), &(*pTotCount));
   }
   //폴더 깊이와 이전 최하위 폴더 깊이 비교
   if( (*pTotCount) < (*pCount) )    
   {
    (*pTotCount) = (*pCount);
   }
  }
  bResult = FindNextFile(hFile, &fData);
 }

 FindClose(hFile);
 (*pCount)--;
}

위로 스크롤