_splitpath

Description

Breaks a path name into components.

#include <stdlib.h>

void _splitpath( char *path, char *drive, char *dir, char *fname, char *ext );

path Full path name  
drive Drive letter  
dir Directory path  
fname Filename  
ext File extension  

Remarks

The _splitpath routine breaks a full path name into its four components. The path argument should point to a buffer containing the complete path name. The maximum size necessary for each buffer is specified by the manifest constants _MAX_DRIVE, _MAX_DIR, _MAX_FNAME, and _MAX_EXT, defined in STDLIB.H. The other arguments point to the 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. Forward slashes (/), backslashes (\), or both may be present in path.
fname Contains the base filename without any extensions.
ext Contains the filename extension, if any, including the leading period (.).

The return parameters will contain empty strings for any path-name components not found in path. You can pass a NULL pointer to _splitpath for any component you don't wish to receive.

Return Value

None.

Compatibility

Standards:None

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:DOS32X

See Also

_fullpath, _makepath

Example

/* MAKEPATH.C */

#include <stdlib.h>

#include <stdio.h>

void 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", "\\c70\\clibref\\", "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( " Dir: %s\n", dir );

printf( " Filename: %s\n", fname );

printf( " Ext: %s\n", ext );

}

Output

Path created with _makepath: c:\c70\clibref\makepath.c

Path extracted with _splitpath:

Drive: c:

Dir: \c70\clibref\

Filename: makepath

Ext: .c