_splitpath -- Decompose Path Name

Format

#include <stdlib.h>
void _splitpath(char *path, char *drive, char *dir,
                    char *fname, char *ext);

Language Level: Extension
_splitpath decomposes an existing path name path into its four components. The path should point to a buffer containing the complete path name.

The maximum size necessary for each buffer is specified by the _MAX_DRIVE, _MAX_DIR, _MAX_FNAME, and _MAX_EXT constants defined in <stdlib.h>. The other arguments point to the following buffers used to store the path name elements:

Buffer Description
drive Contains the drive letter followed by a colon (:) if a drive is specified in path.
dir Contains the path of subdirectories, if any, including the trailing slash. Slashes (/), backslashes (\), or both may be present in path.
fname Contains the base file name without any extensions.
ext Contains the file name extension, if any, including the leading period (.).

You can specify NULL for any of the buffer pointers to indicate that you do not want the string for that component returned.

The return parameters contain empty strings for any path name components not found in path.

Return Value
There is no return value.

Example
This example builds a file name path from the specified components, and then extracts the individual components.

#include <stdio.h>
#include <stdlib.h>
int main(void)
{
   char path_buffer[_MAX_PATH];
   char drive[_MAX_DRIVE];
   char dir[_MAX_DIR];
   char fname[_MAX_FNAME];
   char ext[_MAX_EXT];
   _makepath(path_buffer, "c", "qc\\bob\\eclibref\\e", "makepath", "c");
   printf("Path created with _makepath: %s\n\n", path_buffer);
   _splitpath(path_buffer, drive, dir, fname, ext);
   printf("Path extracted with _splitpath:\n");
   printf("drive: %s\n", drive);
   printf("directory: %s\n", dir);
   printf("file name: %s\n", fname);
   printf("extension: %s\n", ext);
   return 0;
   /**********************************************************************
      The output should be:
      Path created with _makepath: c:qc\bob\eclibref\e\makepath.c
      Path extracted with _splitpath:
      drive: c:
      directory: qc\bob\eclibref\e\
      file name: makepath
      extension: .c
   **********************************************************************/
}



_fullpath -- Get Full Path Name of Partial Path
_getcwd -- Get Path Name of Current Directory
_getdcwd -- Get Full Path Name of Current Directory
_makepath -- Create Path
<stdlib.h>