3

How do I get the time that a file was created?

What I have found: The lfs library for Lua contains a method to get file attributes. However, the only ones that seem to get close to answering my question are those:

  • access - time of last access
  • modification - time of last data modification
  • change - time of last file status change

None of them, by their descriptions, check for the creation time specifically. I've been googling for a while and can't find the answer.

EDIT: I'm on a windows system.

Xonok
  • 133
  • 5

2 Answers2

4

Windows command-line provides the argument /T:C to show the file creation date/time when used in context of dir command.

So, you can use the io.popen function as follows:

local sOut = io.popen( "dir /T:C *files*", "r" )
local sData = sOut:read "*a"
-- process sData as string to filter content as your needs
hjpotter92
  • 78,589
  • 36
  • 144
  • 183
2

At least on Unix, you can't. There are three members related to time in struct stat:

  • st_atime Time of last access.
  • st_mtime Time of last data modification.
  • st_ctime Time of last status change.

Some people misunderstood st_ctime for file creation time, but that's not true. File creation time is not preserved in Unix-style system.

The closest is last status change time, which you could get with lfs library, or, read How can I get last modified timestamp in Lua for a solution without third-part libraries.

Community
  • 1
  • 1
Yu Hao
  • 119,891
  • 44
  • 235
  • 294