| [ CnUnix ] in KIDS 글 쓴 이(By): belami (- 커피 -) 날 짜 (Date): 1995년09월30일(토) 20시14분12초 KDT 제 목(Title): [A][A] 디렉토리를 읽을 때 scandir()을 쓰면 코드 한 줄로 위와 같은 일을 할 수 있습니다. Example이 없는 OS를 위해 HPUX의 매뉴얼페이지에 있는 샘플코드를 옮깁니다. #include <sys/types.h> #include <stdio.h> #include <dirent.h> extern int scandir(); extern int alphasort(); main() { int num_entries, i; struct dirent **namelist, **list; if ((num_entries = scandir("/tmp", &namelist, NULL, alphasort)) <{ fprintf(stderr, "Unexpected error\n"); exit(1); } printf("Number of entries is %d\n", num_entries); if (num_entries) { printf("Entries are:"); for (i=0, list=namelist; i<num_entries; i++) { printf(" %s", (*list)->d_name); free(*list); *list++; } free(namelist); printf("\n"); } printf("\n"); exit(0); } - 끝. |