linux怎么得到一个文件的最后修改时间?
我现在得到了一个字符串,例如: "\home\1.c ",我该用什么函数得到它的文件属性(文件最后修改时间,创建时间等)啊?
[解决办法]
C/C++标准库没有提供这样的设施,所以这个问题在不同平台上的实现方式可能不大一样。
不过大多数的C标准库提供了“_stat”函数和结构体可以做类似的事情,详细的查查MSDN吧。
[解决办法]
#include <sys/stat.h>
int stat(const char *restrict pathname, struct
stat *restrict buf);
int fstat(int filedes, struct stat *buf);
int lstat(const char *restrict pathname, struct
stat *restrict buf);
struct stat {
mode_t st_mode; /* file type & mode (permissions) */
ino_t st_ino; /* i-node number (serial number) */
dev_t st_dev; /* device number (file system) */
dev_t st_rdev; /* device number for special files */
nlink_t st_nlink; /* number of links */
uid_t st_uid; /* user ID of owner */
gid_t st_gid; /* group ID of owner */
off_t st_size; /* size in bytes, for regular files */
time_t st_atime; /* time of last access */
time_t st_mtime; /* time of last modification */
time_t st_ctime; /* time of last file status change */
blksize_t st_blksize; /* best I/O block size */
blkcnt_t st_blocks; /* number of disk blocks allocated */
};
就是st_mtime那值