views:

275

answers:

4

When im naming a variable for a directory should i end the variable name with path, folder or directory.

Im writing my code in .net..

+2  A: 

I use "path" to refer to the full path of a file (directory + file name). I'd recommend "folder", "directory" or even "dir".

Dustin Campbell
+1  A: 

It doesn't matter - all are more or less synonymous and should be clearly understood in context.

The only caveat I'd say is that path could be a web location or a file, where folder and directory won't be, if that helps your decision.

annakata
A: 

There is no official coding convention for this out there. I prefer this style:

*Path (SystemPath, AppPath) for "C:\Windows\Systems32" or "file://..." or "../../bin/Debug"

*Dir (ImageDir, ThemeDir) for ("img" or "theme")

michl86
+1  A: 

Ok, first some definitions:

  • A Path is an address within the file system, it can point to either a file or a directory.
  • A Directory can contain multiple files and subdirectories.
  • A File can be accessed via it's full path (e.g. C:\Temp\Foo.txt), or a relative path (..\Temp\Foo.txt). (I would consider the file name (Foo.txt) to be a relative path as well).

Therefore, if a variable is ambiguous, (i.e. could point to either a file or a directory, like when recursively walking through the directory tree,) I would call it FooPath.

If your variable always points to one file, I would call it FooFile

If your variable is always the name of a directory, and never of a file, I would let this reflect by calling it FooDirectory, or FooDir for short.

But of course the most important rule is consistency: Choose one naming convention and stick with it. Do not call one variable FooDirectory, the next BarDir and the third BuzzFolder.

Treb