2

I'd like to read file access times in a portable way. I found accessTime in System.Posix.Files, but it's POSIX only. Is there a portable, cross-platform way that would work both on Windows and POSIX systems?

Petr
  • 62,528
  • 13
  • 153
  • 317

4 Answers4

6

How about System.Directory.getModificationTime for modification time? For access time I'm not sure there is a portable way.

augustss
  • 22,884
  • 5
  • 56
  • 93
4

On Windows you can use System.Win32.getFileTime function, second time - is last access time. How i know - no crossplatform way for this task.

Ilya Rezvov
  • 914
  • 5
  • 13
2

You can use unix-compat to get both Windows and POSIX support for a lot of the functionality in the unix package.

Michael Snoyman
  • 31,100
  • 3
  • 48
  • 77
  • 1
    I almost rejoiced that the problem is solved so easily, but unfortunately, looking at the implementation of the portable part, it doesn't really read access time, [it just copies modification time into it](https://github.com/jystic/unix-compat/blob/master/src/System/PosixCompat/Files.hsc#L314). – Petr Apr 08 '13 at 18:38
  • Wow, that's too bad. I'm glad to know of that caveat at least. – Michael Snoyman Apr 09 '13 at 01:59
0

As of directory-1.2.3 there is now System.Directory.getAccessTime.