linux目录操作一些函数

DIR *opendir(const char *name);  打开目录以获取目录指针

ep:    DIR *dirp = oepndir(path);  path : 路径名目录 

struct dirent *readdir(DIR *dirp);读取目录项

struct dirent *ep = readdir(dirp);      dirp : 目录指针


char buf[256] = {0};
getcwd(buf,256);      //获取绝对路径,将路径存储到buf里

获取文件的元数据(类型,权限,大小等)用下面的这些函数

int stat(const cahr *path,struct stat *buf);

int fstat(int fd,struct stat *buf);

int lstat(const char *path,struct stat *buf);

path:文件路径   fd: 文件描述符  buf: 属性结构体

 

struct stat {

dev_t   st_dev;                //普通文件所在存储器的设备好

mode_t  st_mode;         //文件权限,类型

ino_t   st_ino;                //文件索引号

nlink_t  st_nlink;            //引用计数

uid_t   st_uid;                  //文件所有者的UID

gid_t   st_gid;                  //文件所属组的GID

dev_t  st_rdev;                //特殊文件的设备好

off_t    st_size;                 //文件大小

blkcnt_t  st_blocks;        //文件所占数据块个数

time_t st_atime;           // 最近访问时间

time_t st_mtime;        // 最近修改时间

time_t st_ctime;         //最近属性更改时间

blksize_t st_blksize:   //写数据块建议值

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值