여기에 디렉토리가 주어집니다. 우리의 임무는 디렉토리의 모든 파일과 하위 디렉토리를 나열하는 C 프로그램을 만드는 것입니다.
디렉토리 파일 세트가 저장될 장소/영역/위치입니다.
하위 디렉토리 는 루트 디렉토리 내부의 디렉토리이며 다른 하위 디렉토리를 가질 수 있습니다.
C 프로그래밍 언어에서는 디렉토리의 모든 파일과 하위 디렉토리를 쉽게 나열할 수 있습니다. 아래 프로그램은 디렉토리의 모든 파일과 하위 디렉토리를 나열하는 방법을 보여줍니다.
// 디렉토리의 모든 파일과 하위 디렉토리를 나열하는 C 프로그램
예시
#include <stdio.h>
#include <dirent.h>
int main(void){
struct dirent *files;
DIR *dir = opendir(".");
if (dir == NULL){
printf("Directory cannot be opened!" );
return 0;
}
while ((files = readdir(dir)) != NULL)
printf("%s\n", files->d_name);
closedir(dir);
return 0;
} 출력
cprograms .. prog1.c prog2.c prog3.c ... prog41.c This will return all files and sub-directory of the current directory.