#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <dirent.h>
#include <errno.h>
#include <string.h>
void ls(char* src)
{
DIR* dir = opendir(src);
char path[256] = {0};
if(dir == NULL)
perror("opendir"),exit(-1);
struct dirent* ent=NULL;
while((ent = readdir(dir)))
{
if(ent->d_type == 4)
{
printf("目录 %s\n",ent->d_name);
if(strcmp(".",ent->d_name) == 0 || strcmp("..",ent->d_name) == 0)
continue;
sprintf(path,"%s//%s",src,ent->d_name);
ls(path);
}
if(ent->d_type == 8)
printf("文件 %s\n",ent->d_name);
}
}
int main(int argc,char* argv[])
{
ls("..");
return 0;
}
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <dirent.h>
#include <errno.h>
#include <string.h>
void ls(char* src)
{
DIR* dir = opendir(src);
char path[256] = {0};
if(dir == NULL)
perror("opendir"),exit(-1);
struct dirent* ent=NULL;
while((ent = readdir(dir)))
{
if(ent->d_type == 4)
{
printf("目录 %s\n",ent->d_name);
if(strcmp(".",ent->d_name) == 0 || strcmp("..",ent->d_name) == 0)
continue;
sprintf(path,"%s//%s",src,ent->d_name);
ls(path);
}
if(ent->d_type == 8)
printf("文件 %s\n",ent->d_name);
}
}
int main(int argc,char* argv[])
{
ls("..");
return 0;
}