Function: set-file-times
set-file-times is a function defined in fileio.c.
Signature
(set-file-times FILENAME &optional TIMESTAMP FLAG)
Documentation
Set times of file FILENAME to TIMESTAMP.
If optional FLAG is nofollow, do not follow FILENAME if it is a
symbolic link. Set both access and modification times. Return t on
success, else nil. Use the current time if TIMESTAMP is nil.
TIMESTAMP is in the format of current-time.
Other relevant functions are documented in the file group.
Probably introduced at or before Emacs version 22.1.
Shortdoc
;; file
(set-file-times "/tmp/foo")
Source Code
// Defined in /usr/src/emacs/src/fileio.c
{
int nofollow = symlink_nofollow_flag (flag);
struct timespec ts[2];
if (!NILP (timestamp))
ts[0] = ts[1] = lisp_time_argument (timestamp);
else
ts[0].tv_nsec = ts[1].tv_nsec = UTIME_NOW;
/* If the file name has special constructs in it,
call the corresponding file name handler. */
Lisp_Object
absname = Fexpand_file_name (filename, BVAR (current_buffer, directory)),
handler = Ffind_file_name_handler (absname, Qset_file_times);
if (!NILP (handler))
return calln (handler, Qset_file_times, absname, timestamp, flag);
Lisp_Object encoded_absname = ENCODE_FILE (absname);
check_vfs_filename (encoded_absname, "Trying to set access times of"
" file within special directory");
if (utimensat (AT_FDCWD, SSDATA (encoded_absname), ts, nofollow) != 0)
{
#ifdef MSDOS
/* Setting times on a directory always fails. */
if (file_directory_p (encoded_absname))
return Qnil;
#endif
report_file_error ("Setting file times", absname);
}
return Qt;
}