The naming standard for path components

cross platformfilenameslanguage-agnosticpathterminology

I keep getting myself in knots when I am manipulating paths and file names because I don’t follow a naming standard for path components.

Consider the following toy problem (Windows example, but hopefully the answer should be platform independent). You have been given the path of a folder:

C:\users\OddThinking\Documents\My Source\

You want to walk the folders underneath and compile all the .src files to .obj files.

At some point you are looking at the following path:

C:\users\OddThinking\Documents\My Source\Widget\foo.src

How would you name the following path components?

A. foo
B. foo.src
C. src
D. .src
E. C:\users\OddThinking\Documents\My Source\ (i.e. the absolute path of the root)
F. Widget\foo.src (i.e. the relative path of the file)
G. Widget\
H. C:\users\OddThinking\Documents\My Source\Widget\
I. C:\users\OddThinking\Documents\My Source\Widget\foo.src

Here is my attempt:

A. Base name? Basename?

B. File name? Filename? The difference is important when choosing identifier names, and I am never consistent here.

C. Extension?

D. Extension? Wait, that is what I called C. Should I avoid storing the dot, and just put it in when required? What if there is no dot on a particular file?

E. ?

F. ?

G. Folder? But isn’t this a Windows-specific term?

H. Path name? Pathname? Path?

I. File name? Wait, that is what I called C. Path name? Wait, that is what I called H.

Best Answer

I think your search for a "standard" naming convention will be in vain. Here are my proposals, based on existing, well-known programs:

A) C:\users\OddThinking\Documents\My Source\Widget\foo.src

Vim calls it file root (:help filename-modifiers)

B) C:\users\OddThinking\Documents\My Source\Widget\foo.src

file name or base name

C) C:\users\OddThinking\Documents\My Source\Widget\foo.src (without dot)

file/name extension

D) C:\users\OddThinking\Documents\My Source\Widget\foo.src (with dot)

also file extension. Simply store without the dot, if there is no dot on a file, it has no extension

E) C:\users\OddThinking\Documents\My Source\Widget\foo.src

top of the tree
No convention, git calls it base directory

F) C:\users\OddThinking\Documents\My Source\Widget\foo.src

path from top of the tree to the leaf
relative path

G) C:\users\OddThinking\Documents\My Source\Widget\foo.src

one node of the tree
no convention, maybe a simple directory

H) C:\users\OddThinking\Documents\My Source\Widget\foo.src

dir name

I) C:\users\OddThinking\Documents\My Source\Widget\foo.src

full/absolute path