Function: file-name-sans-extension

file-name-sans-extension is a byte-compiled function defined in files.el.gz.

Signature

(file-name-sans-extension FILENAME)

Documentation

Return FILENAME sans final "extension" and any backup version strings.

The extension, in a file name, is the part that begins with the last ., except that a leading . of the file name, if there is one, doesn't count. Any extensions that indicate backup versions and version strings are removed by calling file-name-sans-versions, which see, before looking for the "real" file extension.

Other relevant functions are documented in the file-name group.

View in manual

Probably introduced at or before Emacs version 19.29.

Shortdoc

;; file-name
(file-name-sans-extension "/tmp/foo.txt")
    => "/tmp/foo"

Aliases

f-no-ext

Source Code

;; Defined in /usr/src/emacs/lisp/files.el.gz
(defun file-name-sans-extension (filename)
  "Return FILENAME sans final \"extension\" and any backup version strings.
The extension, in a file name, is the part that begins with the last `.',
except that a leading `.' of the file name, if there is one, doesn't count.
Any extensions that indicate backup versions and version strings are
removed by calling `file-name-sans-versions', which see, before looking
for the \"real\" file extension."
  (save-match-data
    (let ((file (file-name-sans-versions (file-name-nondirectory filename)))
	  directory)
      (if (and (string-match "\\.[^.]*\\'" file)
	       (not (eq 0 (match-beginning 0))))
	  (if (setq directory (file-name-directory filename))
	      ;; Don't use expand-file-name here; if DIRECTORY is relative,
	      ;; we don't want to expand it.
	      (concat directory (substring file 0 (match-beginning 0)))
	    (substring file 0 (match-beginning 0)))
	filename))))