mkdir()
#include #include int mkdir(const char *pathname, mode_t mode);
opendir()、fdopendir()
//翻开一个文件夹流,回来一个绑定了这个流的指针,成功回来一个指针,失利回来NULL设errno#include #include DIR *opendir(const char *name);DIR *fdopendir(int fd);
readdir()
//回来一个代表了目录流里下一个目录进口的结构体指针a) #include struct dirent *readdir(DIR *dirp);struct dirent { ino_t d_ino; /* inode number */ off_t d_off; /* not an offset; see NOTES */ unsigned short d_reclen; /* length of this record */ unsigned char d_type; /* type of file; not supported by all filesystem types */ char d_name[256]; /* filename */};
telldir()
//回来当时的目录流的方位,失利回来-1设errno#include long telldir(DIR *dirp);
seekdir()
设置下次读取目录的方位#include void seekdir(DIR *dirp, long loc);
rewinddir()
//将目录流的方位指针重设到目录的最初#include #include void rewinddir(DIR *dirp);
dirfd()
//回来绑定了目录流的文件描述符#include #include int dirfd(DIR *dirp);
closedir()
封闭dirp绑定的目录流,成功回来0.失利回来-1设errnoa) #include #include int closedir(DIR *dirp);
rmdir()
//删去指定途径的目录,这个目录有必要是空的,成功回来0.失利回来-1#include int rmdir(const char *pathname);
/*——————————————————————————————–hw.c编程完成打印指定目录中的内容, 要求子目录中的内容也要打印出来——————————————————————————————–*/#include#include#include#include#include#includevoid print(char *path){ DIR *dir=opendir(path); if(NULL==dir) perror(“opendir”),exit(-1); printf(“翻开%s目录成功\n”,path); struct dirent* ent=NULL; while(ent=readdir(dir)){ printf(“type:%d,name:%s\n”,ent-》d_type,ent-》d_name); if(4==ent-》d_type&&*ent-》d_name!=‘。’){ char buf[200];// char buf[]=“。/”; //ATTENTION: 当时工作目录里找“。/Code”是不可的,得在“。./。./160510/Code”里边找// strcat(buf,path); // strcpy(buf,path); strcat(buf,“/”); strcat(buf,ent-》d_name); print(buf); } } int res=closedir(dir); if(-1==res) perror(“closedir”),exit(-1);}int main(){ print(“。./。./160510”); return 0;}