|
MS Windows의 특성상 파일 갯수 카운트를 한번에 하는 방법이 없습니다. 어쩔 수 없는 부분입니다.
손성민 님이 쓰신 글 :
: 볼랜드툴을 사용하진 않지만..^^;
:
: 특정경로가 포함되는 모든 하위경로들을 포함해서... 파일의 갯수를 카운트하는 놈입니다.
: findfirstfile() / findnextfile() 함수를 이용해서......
: 현재 아래와 같이 구현을 했씁니다..
:
: 그런데 문제는......엄청난 I/O 발생과 함께.... 가장 중요한 시간이 너무나 오래 걸린다는 겁니다..ㅠ_ㅡ
: 이 문제를 근복적..혹은 부분적으로라도 해결할 수 있는 방법이 없을까요?
: 특별히 알고리즘의 수정은 필요없을 거라고 생각합니다만..(물론;;; 파일시스템 구조를 전혀 모르기 떔에...ㅠㅠ)
: 작은 도움이라도 주시면 감사드리겠습니다.
:
:
:
: #include <windows.h>
: #include "sys/stat.h"
: #include <stdio.h>
:
: long ResearchFileNumber(char *szSearchPath);
: long FindFileRecursive(char *_path);
:
: /*************************************************************************
: // Test main()
:
: void main()
: {
: char szSearchPath[]="c:\\windows"; //Search path
: printf("%d", ResearchFileNumber(szSearchPath));
: }
:
: *************************************************************************/
:
: long ResearchFileNumber(char *szSearchPath)
: {
: long nCounter=0;
:
: struct _stat stat;
: int iResult;
: char cBuf[MAX_PATH * 2 + 1 ]="";
:
: iResult = _stat(szSearchPath, &stat);
:
: if(iResult == 0)
: {
: if(stat.st_mode & _S_IFDIR) //Directory
: wsprintf(cBuf,"%s*.*",szSearchPath);
: else
: wsprintf(cBuf,"%s",szSearchPath);
: return FindFileRecursive(cBuf);
: }
: return -1;
: }
:
: long FindFileRecursive(char *_path)
: {
: long nFileCounter=0;
: long nTempCounter=0;
:
: HANDLE hSrch;
: WIN32_FIND_DATA wfd;
: BOOL bResult = TRUE;
:
: char fname[MAX_PATH]="";
: char drive[_MAX_DRIVE]="";
: char dir[MAX_PATH]="";
: char newpath[MAX_PATH]="";
:
: hSrch = FindFirstFile(_path, &wfd);
:
: if(hSrch == INVALID_HANDLE_VALUE)
: return -1;
:
: while(bResult)
: {
: _splitpath(_path, drive, dir, NULL, NULL);
: if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
: {
: if(wfd.cFileName[0] != '.')
: {
: wsprintf(newpath,"%s%s%s\\*.*", drive, dir, wfd.cFileName);
: nTempCounter = FindFileRecursive(newpath);
: nFileCounter += nTempCounter;
: }
: }
: else
: nFileCounter++;
: bResult = FindNextFile(hSrch, &wfd);
:
: if(hSrch==INVALID_HANDLE_VALUE)
: {
: while(hSrch!=INVALID_HANDLE_VALUE)
: bResult = FindNextFile(hSrch, &wfd);
: }
: }
: FindClose(hSrch);
: return nFileCounter;
: }
|