获取文件属性
来源:互联网 发布:win2008r2安装数据库 编辑:程序博客网 时间:2024/05/21 22:21
描述:获取文件的用户id,组id,大小,最后访问时间,最后修改时间。
要求:输入文件名,打印输出该文件用户id,组id,大小,最后访问时间,最后修改时间。
知识点:int stat(const char *restrict pathname, struct stat *restrict buf);stat结构体
stat结构体:
struct stat {
mode_t st_mode; //文件的类型和存取的权限
ino_t st_ino; //inode节点号
dev_t st_dev; //设备号码
dev_t st_rdev; //特殊设备号码
nlink_t st_nlink; //文件的连接数
uid_t st_uid; //文件所有者
gid_t st_gid; //文件所有者对应的组
off_t st_size; //普通文件,对应的文件字节数
time_t st_atime; //文件最后被访问的时间
time_t st_mtime; //文件内容最后被修改的时间
time_t st_ctime; //文件状态改变时间
blksize_t st_blksize; //文件内容对应的块大小
blkcnt_t st_blocks; //文件内容对应的块数量
}
代码:
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<errno.h>
#include<sys/types.h>
#include<time.h>
#include<sys/stat.h>
int main(int argc,char *argv[])
{
struct stat buf;
int res;
if(argc!=2)
{
perror("参数不正确!正确格式:./main filename");
exit(1);
}
res=stat(argv[1],&buf);
if(res<0)
{
perror("stat error");
exit(1);
}
printf("文件用户id:%ld\n",(long)(buf.st_uid));
printf("组id:%ld\n",(long)(buf.st_gid));
printf("文件大小:%lld\n",(long long)buf.st_size);
printf("最后访问时间:%s\n",ctime(&buf.st_atime));
printf("最后修改时间:%s\n",ctime(&buf.st_mtime));
}
- 获取文件属性
- 获取文件属性
- 获取文件属性
- 获取文件属性
- 文件属性获取
- [Python]获取文件属性
- C#获取文件属性
- wince下获取文件属性
- c# 获取文件属性
- QT 获取文件属性
- 获取文件属性并显示
- [Python]获取文件属性
- C#获取设置文件属性
- VC 文件属性获取
- Linux C获取文件属性
- Linux编程获取文件属性
- 获取文件属性SHGetFileInfo
- C++如何获取文件属性
- Oracle to_char格式化函数
- 从一般管理原则看微软的重组 .
- Android聊天软件的开发(二)--数据库
- C#、ASP.NET 遍历图片,去掉图片周边空白
- 明天终于可以休息了啊
- 获取文件属性
- 存储过程使用游标变量返回结果集(推荐)
- Java正则表达式校验邮箱和手机号
- 浅谈oracle中的context(上下文)
- easyUI--panel
- PHP $_POST
- iOS—应用程序本地化
- Oracle的上下文开发--自己定义的Context开发
- 【Data Structure & Algorithm】在排序数组中查找和为定值的两个数