Header File
stdlib.h
Category
Directory Control Routines
Prototype
void _makepath(char *path, const char *drive, const char *dir, const char *name, const char *ext);
void _wmakepath(wchar_t *path, const wchar_t *drive, const wchar_t *dir, const wchar_t *name, const wchar_t *ext);
Description
Builds a path from component parts.
_makepath makes a path name from its components. The new path name is
X:\DIR\SUBDIR\NAME.EXT
where
drive |
= |
X: |
dir |
= |
\DIR\SUBDIR\ |
name |
= |
NAME |
ext |
= |
.EXT |
If drive is empty or NULL, no drive is inserted in the path name. If it is missing a trailing colon (:), a colon is inserted in the path name. |
|
|
If dir is empty or NULL, no directory is inserted in the path name. If it is missing a trailing slash (\ or /), a backslash is inserted in the path name. |
|
|
If name is empty or NULL, no file name is inserted in the path name. |
|
|
If ext is empty or NULL, no extension is inserted in the path name. If it is missing a leading period (.), a period is inserted in the path name. |
|
|
_makepath assumes there is enough space in path for the constructed path name. The maximum constructed length is _MAX_PATH. _MAX_PATH is defined in stdlib.h. |
|
|
_makepath and _splitpath are invertible; if you split a given path with _splitpath, then merge the resultant components with _makepath, you end up with path. |
|
|
If drive is empty or NULL, no drive is inserted in the path name. If it is missing a trailing colon (:), a colon is inserted in the path name.
If dir is empty or NULL, no directory is inserted in the path name. If it is missing a trailing slash (\ or /), a backslash is inserted in the path name.
If name is empty or NULL, no file name is inserted in the path name.
If ext is empty or NULL, no extension is inserted in the path name. If it is missing a leading period (.), a period is inserted in the path name.
_makepath assumes there is enough space in path for the constructed path name. The maximum constructed length is _MAX_PATH. _MAX_PATH is defined in stdlib.h.
_makepath and _splitpath are invertible; if you split a given path with _splitpath, then merge the resultant components with _makepath, you end up with path.
Return Value
Example
#include <dir.h> #include <string.h> #include <stdio.h> #include <stdlib.h> int main(void) { char s[_MAX_PATH]; char drive[_MAX_DRIVE]; char dir[_MAX_DIR]; char file[_MAX_FNAME]; char ext[_MAX_EXT]; getcwd(s,_MAX_PATH); /* get current working directory */ if (s[strlen(s)-1] != '\\') strcat(s,"\\"); /* append a trailing \ character */ _splitpath(s,drive,dir,file,ext); /* split the string to separate elems */ strcpy(file,"DATA"); strcpy(ext,".TXT"); _makepath(s,drive,dir,file,ext); /* merge everything into one string */ puts(s); /* display resulting string */ return 0; }
Portability
|
POSIX |
Win32 |
ANSI C |
ANSI C++ |
_makepath |
|
+ |
|
|
_wmakepath |
|
+ |
|
|
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|