The FILE_BASENAME function returns the basename 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 basename is the final rightmost segment of the file path; it is usually a file, but can also be a directory name. See Rules used by FILE_BASENAME for additional information.
FILE_BASENAME is based on the standard UNIX
Result = FILE_BASENAME(Path [, RemoveSuffix] [, /FOLD_CASE])
A scalar string or string array containing the basename for each element of the Path argument.
A scalar string or string array containing paths for which the basename 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.
An optional scalar string or 1-element string array specifying a filename suffix to be removed from the end of the basename, if present.
By default, FILE_BASENAME follows the case sensitivity policy of the underlying operating system when attempting to match a string specified by the RemoveSuffix argument. By default, matches are case sensitive on UNIX platforms, and case insensitive on Microsoft Windows platforms. The FOLD_CASE keyword is used to change this behavior. Set it to a non-zero value to cause FILE_BASENAME to do all string matching case insensitively. Explicitly set FOLD_CASE equal to zero to cause all string matching to be case sensitive.
FILE_BASENAME makes a copy of the input file path string, then modifies the copy according to the following rules:
The following command prints the basename of an IDL
.pro file, removing the
PRINT, FILE_BASENAME('/usr/local/rsi/idl/lib/dist.pro', '.pro')
Similarly, the following command prints the basenames of all
.pro files in the
lib subdirectory of the IDL distribution that begin with the letter "I," performing a case insensitive match for the suffix:
PRINT, FILE_BASENAME(FILE_SEARCH(FILEPATH('lib')+'/i*.pro'), '.pro', /FOLD_CASE)
FILE_DIRNAME, PATH_SEP, STREGEX, STRMID, STRPOS, STRSPLIT