Function: file-newer-than-file-p

file-newer-than-file-p is a function defined in fileio.c.

Signature

(file-newer-than-file-p FILE1 FILE2)

Documentation

Return t if file FILE1 is newer than file FILE2.

If FILE1 does not exist, the answer is nil; otherwise, if FILE2 does not exist, the answer is t.

Other relevant functions are documented in the file group.

View in manual

Probably introduced at or before Emacs version 18.

Shortdoc

;; file
(file-newer-than-file-p "/tmp/foo" "/tmp/bar")
    e.g. => nil

Source Code

// Defined in /usr/src/emacs/src/fileio.c
{
  struct stat st1, st2;

  CHECK_STRING (file1);
  CHECK_STRING (file2);

  Lisp_Object absname1 = expand_and_dir_to_file (file1);
  Lisp_Object absname2 = expand_and_dir_to_file (file2);

  /* If the file name has special constructs in it,
     call the corresponding file name handler.  */
  Lisp_Object handler = Ffind_file_name_handler (absname1,
						 Qfile_newer_than_file_p);
  if (NILP (handler))
    handler = Ffind_file_name_handler (absname2, Qfile_newer_than_file_p);
  if (!NILP (handler))
    return call3 (handler, Qfile_newer_than_file_p, absname1, absname2);

  int err1;
  if (emacs_fstatat (AT_FDCWD, SSDATA (ENCODE_FILE (absname1)), &st1, 0) == 0)
    err1 = 0;
  else
    {
      err1 = errno;
      if (err1 != EOVERFLOW)
	return file_attribute_errno (absname1, err1);
    }
  if (emacs_fstatat (AT_FDCWD, SSDATA (ENCODE_FILE (absname2)), &st2, 0) != 0)
    {
      file_attribute_errno (absname2, errno);
      return Qt;
    }
  if (err1)
    file_attribute_errno (absname1, err1);

  return (timespec_cmp (get_stat_mtime (&st2), get_stat_mtime (&st1)) < 0
	  ? Qt : Qnil);
}