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