먼저 _findfirst 함수를 이용하여 핸들을 얻는다. 이 때, 첫 번째 파라메터에
폴더 및 찾고자하는 파일 명(또는 확장자)을 설정한다. 이 후 _findnext 함수를
이용하여 폴더 내 모든 파일을 검색하며, 결과가 -1이 리턴되면 종료한다.
#include <stdio.h>
#include <io.h>
#include <conio.h>
void main()
{
_finddata_t fd;
long handle;
int result = 1;
handle = _findfirst(".\\*.*", &fd); //현재 폴더 내 모든 파일을 찾는다.
if (handle == -1)
{
printf("There were no files.\n");
return;
}
while (result != -1)
{
printf("File: %s\n", fd.name);
result = _findnext(handle, &fd);
}
_findclose(handle);
return;
}
[Windows XP, VS2010에서 동작 확인 함]
댓글 없음:
댓글 쓰기