Search code examples
filetimelua

Get file creation time with lua


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.


Solution

  • 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