The FILE_DIRNAME function returns the dirname of a file path. A file path is a string containing one or more segments consisting of names separated by directory delimiter characters (slash (
/) under UNIX, or backslash (
\) under Microsoft Windows). The dirname is all of the file path except for the final rightmost segment, which is usually a file name, but can also be a directory name. See Rules use by FILE_DIRNAME for additional information.
FILE_DIRNAME is based on the standard Unix
Result = FILE_DIRNAME(Path [, /MARK_DIRECTORY])
A scalar string or string array containing the dirname for each element of the Path argument.
\) as the directory separator character, even if the slash (
/) was used in the Path argument.
A scalar string or string array containing paths for which the dirname is desired.
\) character is used to separate directories within a path. For compatibility with UNIX, and general convenience, the forward slash (
/) character is also accepted as a directory separator in the Path argument. However, all results produced by FILE_DIRNAME on Windows platforms use the standard backslash for this purpose, regardless of the separator character used in the input Path argument.
Set this keyword to include a directory separator character at the end of the returned directory name string. Including the directory character allows you to concatenate a file name to the end of the directory name string without having to supply the separator character manually. This is convenient for cross platform programming, as the separator characters differ between operating systems.
FILE_DIRNAME makes a copy of the input path string, and then modifies the copy according to the following rules:
If either of these are present in Path, they are considered to be part of the dirname, and are copied to the result without interpretation by the remaining steps below.
The following statements print the directory in which IDL locates the file
dist.pro when it needs a definition for the DIST function. (DIST is part of the standard IDL user library, included with IDL):
temp = DIST(4) ; Ensure that DIST is compiled PRINT, FILE_DIRNAME((ROUTINE_INFO('DIST', $ /FUNCTION, /SCOURE)).path)
Depending on the platform and location where IDL is installed, IDL prints something like:
FILE_BASENAME, PATH_SEP, STREGEX, STRMID, STRPOS, STRSPLIT