What's in a (file)name?

Seeking a name for an obvious un-named thing

Here's a simple conundrum: Given a file, say:


what are the names for the different parts of it?

The directory (part) is /foo/bar. The non-directory or file part is baz.exe. The extension is .exe.

So what is baz?

Frequently, I've written code that produces an output file based on this "stem" of the input file name, e.g. quux.xlsx might give rise to quux.csv or quux.expanded.csv. And every time, I wonder what to call it.

In linguistics, you might talk about the "stem" of a word, reducing complex word to their most basic form. For example, "fishing", "fished", and "fisher" would reduce to "fish". You might also talk about the "base" or "root" of a word.

Matlab documentation uses "filename". It's not clear what a filename plus extension makes. In their defence, under some early operating systems (CP/M, MS-DOS), the stem is the filename, with the extension being a sort of metadata.

Emacs talks about the "filename-sans-extension". Bit of a mouthful. And French.

Microsoft's developer documentation talk about the "base".

PHP helpfully uses some of the same words but in the opposite direction. baz.exe is the "basename", while baz is the "filename". (Not just PHP either. Some of Python's documentation refers to the filename with extension as the "basename" too. Sheesh.)

Wikipedia confirms this confusion:

Sometimes "filename" is used to mean the entire name, such as the Windows name c:\directory\myfile.txt. Sometimes, it will be used to refer to the components, so the filename in this case would be myfile.txt. Sometimes, it is a reference that excludes an extension, so the filename would be just myfile. Such ambiguity is widespread

It later notes that many operating systems talk about the "base" or "stem".


It's all horribly screwed up. While "base" appears to be the most popular, there are enough situations where it means the exact opposite, that it's a risky term to use anywhere. For my own part, I'll be using "stem".