当前位置: 技术问答>linux和unix
LINUX下文件创建时间问题
来源: 互联网 发布时间:2015-12-17
本文导语: 前提: 我现在在LINUX用C对指定目录A下的文件进行迁移,即当文件从在A目录开始时间算起,三个月后,将文件迁移到目录B中. 问题: 不知道怎么获得文件在A中的创建时间 谢谢!盼回复!!! | 用函数fstat...
前提:
我现在在LINUX用C对指定目录A下的文件进行迁移,即当文件从在A目录开始时间算起,三个月后,将文件迁移到目录B中.
问题:
不知道怎么获得文件在A中的创建时间
谢谢!盼回复!!!
我现在在LINUX用C对指定目录A下的文件进行迁移,即当文件从在A目录开始时间算起,三个月后,将文件迁移到目录B中.
问题:
不知道怎么获得文件在A中的创建时间
谢谢!盼回复!!!
|
用函数fstat、stat
|
#include
#include
#include
int fstat(int filedes, struct stat *buf);
struct stat {
dev_t st_dev; /* device */
ino_t st_ino; /* inode */
mode_t st_mode; /* protection */
nlink_t st_nlink; /* number of hard links */
uid_t st_uid; /* user ID of owner */
gid_t st_gid; /* group ID of owner */
dev_t st_rdev; /* device type (if inode device) */
off_t st_size; /* total size, in bytes */
blksize_t st_blksize; /* blocksize for filesystem I/O */
blkcnt_t st_blocks; /* number of blocks allocated */
这几个值应该就是你想要的
time_t st_atime; /* time of last access */
time_t st_mtime; /* time of last modification */
time_t st_ctime; /* time of last change */
};
#include
#include
int fstat(int filedes, struct stat *buf);
struct stat {
dev_t st_dev; /* device */
ino_t st_ino; /* inode */
mode_t st_mode; /* protection */
nlink_t st_nlink; /* number of hard links */
uid_t st_uid; /* user ID of owner */
gid_t st_gid; /* group ID of owner */
dev_t st_rdev; /* device type (if inode device) */
off_t st_size; /* total size, in bytes */
blksize_t st_blksize; /* blocksize for filesystem I/O */
blkcnt_t st_blocks; /* number of blocks allocated */
这几个值应该就是你想要的
time_t st_atime; /* time of last access */
time_t st_mtime; /* time of last modification */
time_t st_ctime; /* time of last change */
};