0

Looking to a way in lua to get last time an file was modified, on windows

I have seen this post How can I get last modified timestamp in Lua But is a solution for linux :/ can I use io.popen to get the string in windows also?

Cacilda
  • 17
  • 4

2 Answers2

1
function get_file_time(filepath)
  local pipe = io.popen('dir /4/tw "'..filepath..'"')
  local output = pipe:read"*a"
  pipe:close()
  return output:match"\n(%d.-:%S*)"
end

local filepath = [[C:\path\to\your\file.ext]]  -- file must exist
print(get_file_time(filepath))
Egor Skriptunoff
  • 23,359
  • 2
  • 34
  • 64
0

Use luafilesystem the git https://github.com/keplerproject/luafilesystem lfs.attributes(<your file path>).modification is what you searching for

it also work for both Windows and Linux the manual https://keplerproject.github.io/luafilesystem/manual.html

Blanket Fox
  • 377
  • 4
  • 15