Function: file-equal-p

file-equal-p is a byte-compiled function defined in files.el.gz.

Signature

(file-equal-p FILE1 FILE2)

Documentation

Return non-nil if files FILE1 and FILE2 name the same file.

If FILE1 or FILE2 does not exist, the return value is unspecified.

Other relevant functions are documented in the file group.

View in manual

Probably introduced at or before Emacs version 24.1.

Shortdoc

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

Aliases

org-file-equal-p (obsolete since 9.0)

Source Code

;; Defined in /usr/src/emacs/lisp/files.el.gz
(defun file-equal-p (file1 file2)
  "Return non-nil if files FILE1 and FILE2 name the same file.
If FILE1 or FILE2 does not exist, the return value is unspecified."
  (let ((handler (or (find-file-name-handler file1 'file-equal-p)
                     (find-file-name-handler file2 'file-equal-p))))
    (if handler
        (funcall handler 'file-equal-p file1 file2)
      (let (f1-attr f2-attr)
        (and (setq f1-attr (file-attributes (file-truename file1)))
	     (setq f2-attr (file-attributes (file-truename file2)))
             (progn
               ;; Haiku systems change the file's last access timestamp
               ;; every time `stat' is called.  Make sure to not compare
               ;; the timestamps in that case.
               (or (equal f1-attr f2-attr)
                   (when (and (eq system-type 'haiku)
                              (consp (nthcdr 4 f1-attr))
                              (consp (nthcdr 4 f2-attr)))
                     (ignore-errors
                       (setcar (nthcdr 4 f1-attr) nil)
                       (setcar (nthcdr 4 f2-attr) nil))
                     (equal f1-attr f2-attr)))))))))