Linux使用C读取文件目录
来源:互联网 发布:局域网控制电脑软件 编辑:程序博客网 时间:2024/06/05 20:06
简单介绍读取存放信息的结构体:
struct dirent { long d_ino;/* inode number 索引节点号 */ off_t d_off; /* offset to this dirent 在目录文件中的偏移 */ unsignedshort d_reclen;/* length of this d_name 文件名长 */ unsignedchar d_type;/* the type of d_name 文件类型 */ char d_name [NAME_MAX+1]; /* file name (null-terminated) 文件名,最长255字符 */ }
晒出一个示例如下:
#include <stdio.h> #include <dirent.h>#include <stdlib.h>int main(int argc,char *argv[]) { DIR *dirptr = NULL; struct dirent *entry; if(argv[1]==NULL) { printf("please input dir you want to read\n"); exit(-1); } if((dirptr = opendir(argv[1])) == NULL) { printf("open dir !"); return 1; } else { do { entry = readdir(dirptr) ; if(entry!=NULL) { printf("%s\n", entry->d_name); } }while (entry); closedir(dirptr); } return 0; }
对其中的说明:
在Linux下编译此c文件,运行时给出你想要读取目录中文件的目录位置。
dirptr就保存了这些信息,之后,dirptr一次偏移将读取到的目录中的各个文件一次打印出。
- Linux使用C读取文件目录
- 使用linux c 目录操作函数,读取任一目录下的所有目录信息文件信息
- linux c 文件与目录读取
- linux C 读取目录文件并统计文件数
- linux C 读取目录文件并统计文件数
- linux c 读取文件
- C语言读取文件目录树
- 【c++】读取目录下所有文件
- linux,读取目录文件及stat用法
- linux c 读取目录及其子目录下所有.jpg文件的文件名(无后缀)
- Linux C目录与文件
- linux c 扫描文件目录
- linux c 读取文件行数
- Linux C 读取.ini文件
- FindFirstFile读取文件目录
- 读取文件目录
- 目录文件读取
- vc 目录文件读取
- 如何解决java.library.path属性在代码中设置不生效问题
- IOS开发中常用到的宏定义
- hdu1501
- Linux grep命令
- 删除Oracle数据库时常见问题(注册表方面,文件目录方面,环境变量方面)
- Linux使用C读取文件目录
- hdu——poj2470—— Ambiguous permutations
- hdu 1013
- 动手写简单的嵌入式操作系统一
- DC_CheckWatchdog
- java中的BigInteger
- ARM指令集与Thumb指令集的区别
- struts学习(3)——struts核心思想
- 编程之美 1.1 让cpu占用率曲线听你指挥(多核处理器)