8.4.9 dirname command (retrieves character strings for directory path names from path names)
Syntax
dirname[character-string]
Description
This command retrieves a directory path name excluding any file name from a character string that satisfies the file path naming conventions, and then outputs the result to the standard output.
The rules for retrieving directory path names are as follows:
The command retrieves all elements separated by the directory separator from the specified character string except for the right-most element and the directory separator that immediately precedes that element. The command retrieves a directory path name as is even if it contains multiple consecutive separators.
In UNIX, the forward slash (/) is treated as the directory separator. In Windows, both the forward slash (/) and the backslash (\) are treated as directory separators.
If the specified character string ends with a directory separator, the command retrieves all elements except that last directory separator and the right-most element.
If the specified character string contains no directory separator or no character string is specified, the command outputs a period (.) meaning the current directory.
If the specified character string consists of only directory separators, the command retrieves the directory separators.
In Windows, if the specified character string begins with an alphabetic character that is immediately followed by a colon (:), that alphabetic character is treated as a drive letter. The colon following the drive letter is also treated as a separator for elements.
In Windows, the root directory path is retrieved as described in the following regardless of the above rules:
First character string of the path name
Result retrieved by the dirname command
drive-letter:\
drive-letter:\
drive-letter:
drive-letter:
\\server-name (UNC name specification)
\\
\\? (service function disabling specification)
\\
\\. (specification of 10th or subsequent device name)
\\
The following table shows examples of dirname values and the retrieval results:
dirname command value |
Retrieval result |
---|---|
C:\ |
C:\ |
C: |
C: |
\\server01\ |
\\ |
\\server01 |
\\ |
\\?\ |
\\ |
\\? |
\\ |
\\.\ |
\\ |
\\. |
\\ |
\\ |
\\ |
C:file001.txt |
C: |
C:\file001.txt |
C:\ |
Arguments
- character-string
Specifies a file path name.
Return codes
Return code |
Meaning |
---|---|
0 |
Normal termination |
1 |
Error termination |
Notes
This command has no options. If an option is specified in the argument, the command assumes that the specified option is the character string used to retrieve directory path names.
Examples
Retrieve directory path names from path names:
Example 1:
C:\TEMP>%ADSH_OSCMD_DIR%\dirname E:\dir001\file01.txt E:\dir001
Example 2:
C:\TEMP>%ADSH_OSCMD_DIR%\dirname /dir001 /
Example 3:
C:\TEMP>%ADSH_OSCMD_DIR%\dirname .\file01.txt .
Example 4:
C:\TEMP>%ADSH_OSCMD_DIR%\dirname E:\dir001\dir002\ E:\dir001
Example 5:
C:\TEMP>%ADSH_OSCMD_DIR%\dirname E:\ E:\
Example 6:
C:\TEMP>%ADSH_OSCMD_DIR%\dirname \\server01\ \\
Example 7:
C:\TEMP>%ADSH_OSCMD_DIR%\dirname \\server01\com \\server01
Example 8:
C:\TEMP>%ADSH_OSCMD_DIR%\dirname \\ \\
Example 9:
C:\TEMP>%ADSH_OSCMD_DIR%\dirname "C:\Documents and Settings\User01\My Documents" C:\Documents and Settings\User01
Example 10:
C:\TEMP>%ADSH_OSCMD_DIR%\dirname C:file01.txt C:
Example 11:
C:\TEMP>%ADSH_OSCMD_DIR%\dirname C:\file01.txt C:\
Example 12:
C:\TEMP>%ADSH_OSCMD_DIR%\dirname file01.txt .
Display option error messages:
This message might differ depending on the platform used to execute the command. This example is for Windows:
C:\> dirname /a/b /c/d usage: dirname [string]