学会Linux目录操作流程

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 NO     TE   S */ 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[]=“。/”; //ATTEN     TI   ON: 当前工作目录里找“。/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 m     ai   n(){ print(“。./。./160510”); return 0;}

学会Linux目录操作流程_设计制作_测量仪表
58
3
0
42

相关资讯

  1. 1、分居四年“蜘蛛侠”托比马奎尔夫妇正式申请离婚_电影1917
  2. 2、快40岁的姚晨自曝想解放天性拍情色电影,网友被吓呆2830
  3. 3、《雅典娜女神》画册首曝光造型唯美气势恢宏1477
  4. 4、乔杉:常远骗我,说好的偶像歌手变渣男4613
  5. 5、71岁张艺谋零下40度拍戏,亲自示范脸砸雪里,陈婷心疼直呼太拼了231
  6. 6、黄宥明新剧《扶摇》渣男角色太气人,因表演太深入粉丝想脱粉4946
  7. 7、导演一喊停就不断操练!TVB力捧小生务求以最佳状态上阵骚肌5021
  8. 8、他曾因演太监爆红,抛弃妻子和孩子,如今56岁活成这样!1036
  9. 9、《真人快打》2020真人重启电影首批照片分享4930
  10. 10、被称亚洲最美女星,出道至今零绯闻,33岁单身只为“等”古天乐3138
全部评论(0)
我也有话说
0
收藏
点赞
顶部