#include<stdio.h>
#include<dirent.h>
#include<sys/stat.h>
int main(){
char *path = "/root";
DIR* dir = opendir(path);
struct stat statbuf;
struct dirent* read;
chdir(path); //改变工作目录
while((read = readdir(dir)) != NULL){
lstat(read->d_name,&statbuf);
//改变工作目录的意义
//不然获取失败
if(S_ISDIR(statbuf.st_mode)){
printf("DIR_%s\n",read->d_name);
}else{
printf("%s\n",read->d_name);
}
}
chdir("..");
closedir(dir);
return 0;
}