在节点中获取文件创建日期 [英] Get file created date in node

查看:104
本文介绍了在节点中获取文件创建日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在节点I中,我可以使用标准文件stat对象获取文件的修改日期。有没有办法我也可以找到它的创建日期?我在 http://nodejs.org/api/fs.html#fs_class_fs_stats中找不到任何内容文档。

In node I can get a file's modified date using the standard file stat object. Is there a way I can also find its created date? I can't find anything in the http://nodejs.org/api/fs.html#fs_class_fs_stats documentation at all.

推荐答案

是否可以获得文件创建时间取决于操作系统和文件系统。传统的POSIX只定义ctime,这是(相当容易混淆)inode修改日期,而不是其他人提到的创建日期。但是,在某些操作系统上,您可以获得st_birthtimespec或st_birthtime,这是一个真正的创建时间。您需要检查主机操作系统上的sys / stat.h,以查看可用的内容(如果有)。

Whether or not you can get the file creation time depends on the OS and file system. Traditional POSIX only defines ctime, which is (rather confusingly), the inode modification date, not the creation date, as other people have mentioned. However, on some operating systems, you can get st_birthtimespec, or st_birthtime which is a true "create" time. You'll need to check sys/stat.h on your host operating system to see what, if anything, is available.

不幸的是,你是否可以从node.js访问整个stat结构是一个不同的鱼。但至少你可以弄清楚你的操作系统是否支持它并从那里开始。

Unfortunately, whether or not you can access the entire stat structure from node.js is a different kettle of fish. But at least you can figure out if your OS even supports it and go from there.

这篇关于在节点中获取文件创建日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆