#include
#include
#include
#include
#include
#include
void printall(const char *path, int max){
DIR *dir = opendir(path); //产生DIR的指针
if (dir == NULL){
return ;
}
struct dirent *dirent; //系统默认含有的结构体体
int t = 1;
while(dirent = readdir(dir)){
if (!strcmp(dirent->d_name,".")||!strcmp(dirent->d_name,"..")){ //遇到. 和 .. 是跳过
continue;
}
for (t = 1; t < max; ++t){
printf("--");
}
if(dirent->d_type == 4){
printf("[%s]\n",dirent->d_name);
char tmp[100] = {0};
sprintf(tmp,"%s/%s",path,dirent->d_name); // 需要进行地址的拼接,否则不能正确往下执行
printall(tmp,max + 1);
}
printf("%s\n",dirent->d_name);
}
}
int main(void)
{
printall("../../",1);
return 0;
}