Get absolute file path without extension

To get an absolute file path without extension in the buffer, for example. /home/alice/hello.cpp/home/alice/hello, the following code works

(concat (file-name-directory (buffer-file-name)) (file-name-base (buffer-file-name)))

But he looks too verbose. Is there an elegant way or direct function for this?

+4
source share
2 answers
(file-name-sans-extension (buffer-file-name))

Do you use auto-complete? It completes the elisp names, so I found the function in a second.

+5
source

If you often manipulate files in Elisp, I recommend installing f.elthe file and directory API, which adds a large number of utility functions. For example, you can use f-no-extto remove the extension from the path.

0