Product Site

5.4.8.26. lastModified (Attribute)

lastModified get:

Returns the last modified date of the file or directory denoted by the absolute path of the receiver object. The result is a DateTime object, or .nil if the file or directory doesn't exist or the last modified time stamp cannot be retrieved.
lastModified set:

If the file or directory denoted by the absolute path of the receiver object exists, this sets the last modified date of the file or directory. Otherwise it does nothing.

The date parameter must be a DateTime object.

See also method lastAccessed (Attribute).
Example 5.257. File class — lastModified attribute
/* On Windows */
say .File~new("C:\Program Files")~lastModified~class  -- The DateTime class
say .File~new("C:\Program Files")~lastModified        -- e.g. 2018-06-18T11:20:17.000000
say .File~new("dummy")~lastModified                   -- e.g. The NIL object


/* A possible implementation of : touch -c -m -r referenceFile file
   -c, --no-create             do not create any files
   -m                          change only the modification time
   -r, --reference=FILE        use this file's time instead of current time
*/
parse arg referenceFilePath filePath .
file = .File~new(filePath)
if \file~exists then
  return 0         -- OK, not an error
referenceFile = .File~new(referenceFilePath)
referenceDate = referenceFile~lastModified
if referenceDate == .nil then
  return 1         -- KO
file~lastModified = referenceDate
return 0           -- OK