Emacs Lisp: Get File Info

By Xah Lee. Date: . Last updated: .

Get File Info

File Size, Date, Owner, etc

file-attributes
(file-attributes FILENAME &optional ID-FORMAT)

Return a list of attributes of file FILENAME. e.g.

  • file-attribute-type
  • file-attribute-link-number
  • file-attribute-user-id
  • file-attribute-group-id
  • file-attribute-access-time
  • file-attribute-modification-time
  • file-attribute-status-change-time
  • file-attribute-size
  • file-attribute-modes
  • file-attribute-inode-number
  • file-attribute-device-number

see emacs lisp manual

;; get file size in bytes
(let ((xfileAttr
       (file-attributes "~/.emacs.d/init.el")))
  (file-attribute-size xfileAttr))
;; sample value
;; 162

Reference

Emacs Lisp File/Buffer