2
我想用C来读取目录中的所有文件的统计(Linux系统:Fedora的)如何读取文件的时间戳目录
我都宣称这种结构:
struct stat st = {0};
然后我检查目录的存在。
if(stat("/home/gadre/Source",&st) == -1)
{
status = mkdir("/home/gadre/Source", 0777);
}
syslog(LOG_INFO, "Source Directory stage completed\n");
,其中的统计是:
struct stat {
dev_t st_dev; /* ID of device containing file */
ino_t st_ino; /* inode number */
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 ID (if special file) */
off_t st_size; /* total size, in bytes */
blksize_t st_blksize; /* blocksize for file system I/O */
blkcnt_t st_blocks; /* number of 512B 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 status change */
};
现在当我进入我希望检查每个文件的最后修改时间st_mtime 的目录。
任何想法我应该使用什么数据结构......应该先将fd存储在列表中,然后遍历它检查......什么是有效的方法。
谢谢。
嗨,工作感谢,任何想法如何我可以验证文件是否在上次访问后upadated。 例如: 23-09-2014文件已更新(已修改),因此st_atime,st_mtime已更改为23-09-2014。但st_ctime不..因为inode信息将保持不变。 在25-09-2014该文件被修改,因此atime和mtime被更改。 但是,对于在26-09-2014阅读这些统计信息的程序,它应该如何知道它已被修改 – RootPhoenix 2014-09-26 08:10:49
很有必要知道这是一个解决方案,那么可能您可以接受答案。关于你的第二个问题,我记得'st_atim'是文件数据的最后访问时间,即它表明它什么时候被读取,而'st_mtim'是文件数据的最后修改时间,即它已经书面。所以如果你打开的文件只有写属性,应该只修改'st_mtim'。 – deimus 2014-09-26 08:46:30