views:

272

answers:

1

I keep getting myself in knots when I am manipulation paths and file names, because I don't have a common naming system that I use.

I need to come up with a naming standard and stick to it, and I would like to be clear and consistent with others, so I am opening up to learn the canonical answers.

Consider this toy problem: (Windows example, but hopefully answer should be platform independent)

You have been given the full name of a folder: C:\users\OddThinking\Documents\My Source. You want to walk the folders underneath, and compile all the .src to .obj.

At some point you are looking at the following string.

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

So, what identifier names would you use for the parts?

A) foo
B) foo.src
C) src
D) .src
E) C:\users\OddThinking\Documents\My Source\ - i.e. the top of the tree.
F) Widget\foo.src - i.e. the path from the top of the tree to the leaf.
G) Widget - i.e. one node of the tree.
H) C:\users\OddThinking\Documents\My Source\Widget\ - i.e. the name of the folder
I) C:\users\OddThinking\Documents\My Source\Widget\foo.src

Let me give some answers, to get you started.

A) base name?

B) file name? Or is it 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 in in when required? What if there is no dot on a particular file?

H) path name? Or wait, is it just the path?

I) filename. Wait, that is what I called C. Path. Wait, that is what I called H. Maybe H should be the folder name. Isn't "folder" a Windows-specific term, though?

+2  A: 

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

A) vim calls it "file root" (:help filename-modifiers)

B) file name or base name

C) file (name) extension

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

E) no convention, git calls it "base directory"

F) relative path

G) no convention, maybe a simple "directory"

H) dir name

I) full/absolute path

blinry
It's getting off-topic, but be careful with the storage of the extension separate to the dot. You need to handle file names of "foo", "foo." and "foo.txt" (and even "foo.txt.bak".)
Oddthinking