views:

39

answers:

1
  1. What are the origins and reasons for the terms, dirname and basename, referring to the path with the trailing component removed, and the trailing component respectively?
  2. Is the terminology standardized, and where?
  3. Are there alternative or equivalent conventions in use to refer to the splitting of a path in this way?

Update0

In particular, alternatives used on major operating systems or libraries are of interest.

+2  A: 

The terms dirname and basename seem quite straightforward, i.e. "directory name" and "base name within the directory", so I don't think there is any specific reason for these names.

I'm not sure what you mean by "Is the terminology standardized". The calls are part of the POSIX standard (dirname, basename) but they've also been borrowed by many high-level languages like PHP (dirname, basename), Perl and Python.

Other equivalents:

On Windows, the shell API provides the PathRemoveFileSpec and PathStripPath functions, which are similar to dirname and basename.

In Java, the File class provides getParent and getName which do the same thing.

casablanca
Can you link to the relevant examples in POSIX and PHP?
Matt Joiner
Done, also added Perl, Python and Java.
casablanca
Long before the functions were standardized, the utilities [dirname](http://www.opengroup.org/onlinepubs/9699919799/utilities/dirname.html) and [basename](http://www.opengroup.org/onlinepubs/9699919799/utilities/basename.html) were available - [Version 7 UNIX](http://plan9.bell-labs.com/7thEdMan/) had the utilities, but not the functions, for instance.
Jonathan Leffler
@Jonathan Leffer: Thanks for the references. I guessed but wasn't sure that they originated somewhere in UNIX.
casablanca
(Oops: it appears that `dirname`, the command, was not in V7 UNIX after all, though `basename` was, essentially the same as now defined in POSIX.)
Jonathan Leffler
Nice, thanks for adding those.
Matt Joiner