Task

Get and set the modification time of a file.




MODULE ModTime EXPORTS Main;
 
IMPORT IO, Fmt, File, FS, Date, OSError;
 
TYPE dateArray = ARRAY [0..5] OF TEXT;
 
VAR 
  file: File.Status;
  date: Date.T;
 
PROCEDURE DateArray(date: Date.T): dateArray =
  BEGIN
    RETURN 
      dateArray{Fmt.Int(date.year), Fmt.Int(ORD(date.month) + 1), Fmt.Int(date.day),
                Fmt.Int(date.hour), Fmt.Int(date.minute), Fmt.Int(date.second)};
  END DateArray;
 
BEGIN
  TRY
    file := FS.Status("test.txt");
    date := Date.FromTime(file.modificationTime);
    IO.Put(Fmt.FN("%s-%02s-%02s %02s:%02s:%02s", DateArray(date)));          
    IO.Put("\n");
  EXCEPT
  | OSError.E => IO.Put("Error: Failed to get file status.\n");
  END;
END ModTime.