免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: 小雨飞
打印 上一主题 下一主题

在C中如何获取一个文件的生成时间 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2006-08-11 13:02 |只看该作者
原帖由 思一克 于 2006-8-11 10:52 发表
你的问题是什么




我的问题是在用户对某些文件进行查询的时候,需要知道该文件的创建的时间

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
12 [报告]
发表于 2006-08-11 13:07 |只看该作者
原帖由 mq110 于 2006-8-11 13:00 发表
如果系统不支持,获得不了.

我觉得,stat 系统调用返回的 st_ctime 基本上可以认为是文件的创建时间了。

论坛徽章:
0
13 [报告]
发表于 2006-08-11 13:08 |只看该作者
如果特殊的自己可以定义的文件,系统又没有CREATE TIME,自己写到文件中

原帖由 kuaizaifeng 于 2006-8-11 13:02 发表



我的问题是在用户对某些文件进行查询的时候,需要知道该文件的创建的时间

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
14 [报告]
发表于 2006-08-11 13:09 |只看该作者
原帖由 flw 于 2006-8-11 13:07 发表

我觉得,stat 系统调用返回的 st_ctime 基本上可以认为是文件的创建时间了。


如果不修改可以这样认为,如果修改了呢??


time_t        st_ctime;    /* time of last status change */

论坛徽章:
0
15 [报告]
发表于 2006-08-11 13:35 |只看该作者
原帖由 mq110 于 2006-8-11 13:09 发表


如果不修改可以这样认为,如果修改了呢??


time_t        st_ctime;    /* time of last status change */

不知道你的定义是在哪里看到的,我记得st_ctime就是创建时间。
另外还有一个st_atime是最后访问时间,还有一个st_mtime是最后修改时间。

论坛徽章:
0
16 [报告]
发表于 2006-08-11 13:38 |只看该作者
在LINUX上(和HP-UX同),st_ctime也不是真正的创建时间。

Q Is there any command on HP-UX which gives the file creation or modification time in seconds? 'ls -l' gives only hour and minute. I am looking for something like 'ls --full-time' on Linux.

A: There is no file creation time for HP-UX stored in the inode. The inode for a file contains last-modified time (shown by "ls -l"), a last-accessed time (shown by "ls -lu") and an inode change time (shown by "ls -lc"). The latter is often referred to as the "creation time" - even in some man pages - but that is incorrect. This time is also set by such operations as mv, ln, chmod, chown and chgrp. The man page for "stat(2)" discusses this in more detail.

The stat(2) call can be used from perl to get to the modification time seconds. For example, the following perl script will print the last modification time for "foo" in seconds since the epoch

论坛徽章:
0
17 [报告]
发表于 2006-08-11 13:52 |只看该作者
那就写个程序测试一下吧,可惜我手边没有linux或者hpux.

论坛徽章:
0
18 [报告]
发表于 2006-08-11 14:02 |只看该作者
我实验过。

论坛徽章:
0
19 [报告]
发表于 2006-08-11 14:28 |只看该作者

st_ctime应该是创建时间吧

我记得这个成员是表示创建时间的,在stat的帮助里面好像就是这么说的。不过现在没有环境,不能肯定,只是凭记忆好像是这样的。

论坛徽章:
0
20 [报告]
发表于 2006-08-11 14:58 |只看该作者
原帖由 robinliu76 于 2006-8-11 14:28 发表
我记得这个成员是表示创建时间的,在stat的帮助里面好像就是这么说的。不过现在没有环境,不能肯定,只是凭记忆好像是这样的。


man 手册里不是这样说的。
我做过测试的。FC5是我的系统
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP