c 语言 获取文件目录下文件列表

  • 内容
  • 评论
  • 相关
#include <sys/types.h>
#include <dirent.h>
#include <unistd.h>
#include <stdio.h>

int main(){
 DIR *dir;
 struct dirent *ptr;
 dir = opendir("."); ///open the dir

 while((ptr = readdir(dir)) != NULL) ///read the list of this dir
 {
 #ifdef _WIN32
 printf("d_name: %s\n", ptr->d_name);
 #endif
 #ifdef __linux
 printf("d_type:%d d_name: %s\n", ptr->d_type,ptr->d_name);
 #endif
 }
 closedir(dir);
 return 0;
}

评论

1条评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注