Find TEXTFILE (파일 목록 출력하기)
Find TEXTFILE (파일 목록 출력하기)
글. 오상문 sualchi@daum.net
// Find TEXTFILE (*.txt)
// 경로 c:\temp 디렉토리에 있는 텍스트 파일 목록 출력
// DEVCpp 5.11 C language
// 2018/7/27 by Sangmun Oh sualchi@daum.net
// 참조: http://mwultong.blogspot.com/2006/12/c-dir-findfirst-findnext.html
#include <stdio.h>
#include <stdlib.h>
#include <io.h>
#include <errno.h>
#include <string.h>
int main() {
struct __finddata64_t c_file;
intptr_t hFile;
char path[] = "c:\\temp\\*.txt";
if ((hFile = _findfirsti64(path, &c_file)) == -1L) {
switch (errno) {
case ENOENT:
printf("파일 없음\n");
exit(ENOENT);
break;
case EINVAL:
fprintf(stderr, "경로명 오류.\n");
exit(EINVAL);
break;
case ENOMEM:
fprintf(stderr, "메모리 부족 또는 너무 긴 파일명 오류.\n");
exit(ENOMEM);
break;
default:
fprintf(stderr, "기타 오류.\n");
exit(1);
break;
}
} else {
printf("-- 파일 목록 --\n");
do {
if(c_file.name[0] != '.')
printf("%s\n", c_file.name);
} while(_findnexti64(hFile, &c_file) == 0);
_findclose(hFile); // 메모리를 반환
}
return 0;
}
<이상>