Creates a path name from components.
#include <stdlib.h>
void _makepath( char *path, char *drive, char *dir, char *fname, char *ext );
path | Full path-name buffer | |
drive | Drive letter | |
dir | Directory path | |
fname | Filename | |
ext | File extension |
The _makepath routine creates a single path name, composed of a drive letter, directory path, filename, and filename extension. The path argument should point to an empty buffer large enough to hold the complete path name. The constant _MAX_PATH, defined in STDLIB.H, specifies the maximum size path that the _makepath function can handle. The other arguments point to buffers containing the path-name elements:
Buffer | Description |
drive | The drive argument contains a letter (A, B, etc.) corresponding to the desired drive and an optional trailing colon. The _makepath routine will insert the colon automatically in the composite path name if it is missing. If drive is a null character or an empty string, no drive letter and colon will appear in the composite path string. |
dir | The dir argument contains the path of directories, not including the drive designator or the actual filename. The trailing slash is optional, and either forward slashes (\) or backslashes (\) or both may be used in a single dir argument. If a trailing slash (/ or \) is not specified, it will be inserted automatically. If dir is a null character or an empty string, no slash is inserted in the composite path string. |
fname | The fname argument contains the base filename without any extensions. If fname is NULL or points to an empty string, no filename is inserted in the composite path string. |
ext | The ext argument contains the actual filename extension, with or without a leading period (.). The _makepath routine will insert the period automatically if it does not appear in ext. If ext is a null character or an empty string, no period is inserted in the composite path string. |
There are no size limits on any of the above four fields. However, the composite path must be no larger than the _MAX_PATH constant. The _MAX_PATH limit permits a path name much larger than current operating-system versions will handle.
None.
Standards:None
16-Bit:DOS, QWIN, WIN, WIN DLL
32-Bit:DOS32X
/* 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", "\\c60\\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 );
}
Path created with _makepath: c:\c60\clibref\makepath.c
Path extracted with _splitpath:
Drive: c:
Dir: \c60\clibref\
Filename: makepath
Ext: .c