//打开一个目录#include<sys/types.h>#include<dirent.h>
DIR *opendir(constchar*name);
参数一:目录的路径
返回值:成功返回目录指针
失败 NULL//打开一个文件描述符
DIR *fdopendir(int fd);//读取一个目录#include<dirent.h>structdirent*readdir(DIR *dirp);
参数一:需要读取的目录指针
返回值:成功 指向目录信息的结构体指针
NULL 则是读到末尾或失败
//目录信息: structdirent{ino_t d_ino;/* Inode number I_NODE节点*/off_t d_off;/* Not an offset; see below 目录项偏移量*/unsignedshort d_reclen;/* Length of this record 目录项的大小*/unsignedchar d_type;/* Type of file; not supported by all filesystem types 文件的类型 */char d_name[256];/* Null-terminated filename 文件名*/};//文件类型的判断
DT_BLK //This is a block device. 块设备
DT_CHR //This is a character device. 字符设备
DT_DIR //This is a directory.目录文件
DT_FIFO //This is a named pipe (FIFO). 管道文件
DT_LNK //This is a symbolic link. 链接文件
DT_REG //This is a regular file.普通文件
DT_SOCK //This is a UNIX domain socket. 网络通信文件
DT_UNKNOWN //The file type could not be determined. 他也不知道什么类型//关闭一个目录项指针intclosedir(DIR *dirp);//创建一个目录#include<sys/stat.h>intmkdir(constchar*path,mode_t mode);
参数一:目录的名字
参数二:文件权限 0666
返回值:成功 返回0
失败 返回-1//删除一个目录intrmdir(constchar*path);
参数一:目录的路径
//修改文件的权限 mode_tumask(mode_t cmask);
参数一:需要设置的mask的值
权限的设置公式:(0666&~umask &0777).0->1111111111111111
在linux系统里面如果要设置文件的权限必须要配套umask一起计算。
注意:
1、在共享目录中不适用,因为windos与linux的文件系统不一致
2、umask设置的是权限“补码”
intchmod(constchar*path,mode_t mode);(文件拥有者)
S_IRWXU 可读可写可执行
S_IRUSR(S_IREAD) 只读
S_IWUSR(S_IWRITE) 只写
S_IXUSR(S_IEXEC) 执行
------------------(文件的所属组)
S_IRWXG 可读可写可执行
S_IRGRP 只读
S_IWGRP 只写
S_IXGRP 执行
-------------------(其他用户)
S_IRWXO 可读可写可执行
S_IROTH 只读
S_IWOTH 只写
S_IXOTH 执行
标准与系统IO操作文件的步骤:1.打开文件2.读写文件3.关闭文件----------------目录的操作步骤-----------------------1.打开目录2.读取目录的内容3.关闭目录目录的API接口:NAMEopendir, fdopendir - open a directory//打开一个目录SYNOPSIS#include <sys/type...