函数接口
打开目录opendir
#include <sys/types.h>
#include <dirent.h>
DIR *opendir(constchar*name);
功能:打开目录
参数:
name:目录路径
返回值:
成功:目录流指针
失败:-1
关闭目录closedir
#include <sys/types.h>
#include <dirent.h>
int closedir(DIR *dirp);
功能:关闭目录
参数:
dirp:目录流指针
返回值:
成功0
失败-1
readdir读取目录内容
#include <dirent.h>
struct dirent * readdir (DIR *dirp);
功能:读取目录中的内容
参数:
dirp:目录流指针
返回值:
成功:返回结构体指针
读到结尾:NULL
失败:NULL
struct dirent {
ino_t d_ino; /* Inode number */ //文件inode号
off_t d_off; /* Not an offset; see below */
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]; /* Null-terminated filename */ //文件名
};
修改路径chdir()
#include <unistd.h>
int chdir (const char*path);
功能:改变当前所处的路径
参数
path:文件路径
返回值
成功:0
失败:-1