views:

218

answers:

4

After years of programming it's still some of the simple things that keep tripping me up.

Is there a commonly agreed definition of filename ?

Even the wikipedia article confuses the two interpretations.

It starts by defining it as 'a special kind of string used to uniquely identify a file stored on the file system of a computer'. That seems clear enough, and suggests that a filename is a fully qualified filename, specifying the complete path to the file.

However, it then goes on to:

  • talk about basename and extension (so basename would contain an absolute path ?)
  • says that the length of a filename in DOS is limited to 8.3
  • says that a filename without a path part is assumed to be a file in the current working directory (so the filename does not uniquely identify a file)

So, simple questions:

  • what is a correct definition of 'filename' (include references)
  • how should I unambiguously name variables for:
    • a path to a file (which can be absolute/full or relative)
    • a path to a resource that can be a file/directory/socket
A: 

Javadoc for File.getName() method

Dev er dev
I don't see definitions in File.getName().
Adam Liss
+4  A: 

No references, just vernacular from experience. When I'm being specific I tend to use:

path or filespec (or file specification): all of the characters needed to identify a file on a filesystem. The path may be absolute (starting from the root, or topmost, directory) or relative (starting from the currently active directory).

filename: the characters needed to identify a file within the current directory.

extension: characters at the end of the filename that typically identify the type of the file. By convention, the extension usually starts with a dot ("."), and a filename may contain more than one extension.

basename: the filename up to (but not including) the dot that begins the first extension.

Adam Liss
That definition of basename doesn't tally with what basename(1) returns, so don't assume it's universal usage.
Steve Jessop
Just to be picky, I can safely say that there is no such beast as an "absolute" filename. Every filename is relative to some context. the filename "c:\dos.ini" does not represent the same file on your machine and mine.
Stephan Leclercq
@Stephan: that's why I explicitly defined absolute. :-) Do you agree that it's accurate according to common usage, namely that the reference point is generally the machine from which the file is accessed?
Adam Liss
A: 

file·name also file name
(fīl'nām') Pronunciation Key n. A name given to a computer file to distinguish it from other files, often containing an extension that classifies it by type.

@ Dictionary.com

It states that a filename is used to name a file, (just like you name a person). And that it's used to distinguish it from other files. This does not tell you it includes a path, or other file-system imposed attributes. This definition does say that often a filename has an extension. But this definition is very careful... (Which I think is a good thing)

So.. before you start thinking about paths and such, you have to set your scope. Are you in a unix world? Ar you in a dos/windows world?

thijs
A: 

Again no references, but the file name specification depends on the operating system or to be more accurate the file system. Lets start with early versions of DOS (Disk Operating System). File names were 8 character names containing numbers, letters, dashes, and underscores. They were followed by a three, two, one, or even zero character extension used to identify the file type. A dot separated the name from the extension. The name had to be unique in the directory.

You could extend the name by adding a directory name, or series of directory names. a slash character separated the directory names from each other and from the file name. This was usually referred to as the path name. The path was relative to current directory.

Finally in DOS you could include the drive name. Usually a single letter followed by a : and a slash (some systems two slashes). Adding the drive to the path made it an absolute path instead of relative.

Today most of us use long file names which do not follow the old 8 character dot three character pattern. Still many files systems keep such as name and use the long name simply as a pointer to old style identifier.

Jim C