Linux下C语言获取目录中的文件列表

#include <sys/types.h> 

#include <dirent.h> 

#include <unistd.h> 

#include <stdio.h> 

int main(){ 

  DIR *dir; 

  struct dirent *ptr; 

  dir = opendir("/home/zhangyang/kmeans"); 

  while((ptr = readdir(dir)) != NULL) 

    printf("d_name: %s\n", ptr->d_name); 

  closedir(dir); 

  return 0; 

posted @ 2017-05-19 09:34  William已上线  阅读(169)  评论(0)    收藏  举报