linux 编程--目录相关
来源:互联网 发布:java写99乘法表 编辑:程序博客网 时间:2024/04/24 18:04
一.头文件
#include <dirent.h>
二.结构体
struct dirent {#ifndef __USE_FILE_OFFSET64 __ino_t d_ino; __off_t d_off;#else __ino64_t d_ino; __off64_t d_off;#endif unsigned short int d_reclen; unsigned char d_type; char d_name[256];/* We must not include limits.h! */ };
struct __dirstream{void *__fd; /* `struct hurd_fd' pointer for descriptor. */char *__data; /* Directory block. */int __entry_data; /* Entry number `__data' corresponds to. */char *__ptr; /* Current pointer into the block. */int __entry_ptr; /* Entry number `__ptr' corresponds to. */size_t __allocation; /* Space allocated for the block. */size_t __size; /* Total valid data in the block. */__libc_lock_define (, __lock) /* Mutex lock for this structure. */};typedef struct __dirstream DIR;
三.API函数
int closedir(DIR *dirp);
关闭目录
DIR *opendir(const char *dirname);
打开目录
struct dirent *readdir(DIR *dirp);
读目录
void seekdir(DIR *dirp, long loc);
设置目录流目前的读取位置
long telldir(DIR *dirp);
目录流的当前位置
四.例子
#include<sys/types.h>#include<dirent.h>#include<stdio.h>int main(int argc, char *argv[]){DIR*dp;struct dirent*dirp;if (argc != 2){printf("use like ./ls /dev \n");return 0;}if ((dp = opendir(argv[1])) == NULL){printf("can not open dir\n");return 0;}while ((dirp = readdir(dp)) != NULL)printf("%s\n", dirp->d_name);closedir(dp);return 0;}
- linux 编程--目录相关
- Linux目录相关操作
- Linux 相关目录介绍
- linux相关博客目录
- Linux相关文章目录
- linux目录相关
- Linux 目录的相关操作
- linux 查找svn相关目录
- linux: 目录相关常见命令
- linux下mysql相关目录
- Linux系统编程学习笔记(2)-文件状态查询与目录相关
- Linux编程相关 - Notes
- linux编程相关
- Linux编程---时间相关
- Linux 文件相关编程
- C语言数据结构相关编程题目(目录)
- linux文件目录及相关功能
- linux 系统相关学习:目录结构
- USACO Chapter2 The Castle
- video1层不能显示完整视频的解决过程
- osganimationskinning例子
- 可以用第三方工具将jar包打成exe文件
- [设计模式]AbstractFactory抽象工厂模式
- linux 编程--目录相关
- 你不能忽视的HTML代码2精编篇
- android 屏幕旋转
- 关于VMWARE虚拟机安装GHOST版XP后不能硬盘启动问题
- SQL Server 2012 T_SQL新特性之一:使用Snippets代码段
- 720P60的Pixel Clock是74.25MHz
- 数据结构_红黑树
- 该醒醒了
- MySQL 环境变量的配置详细说明(转)