Borland C++ reference

_splitpath

raw OCR

Splits a full path name into its components.

Defined in header <stdlib.h>

Syntax

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

Portability

DOSUNIXWindowsANSI CC++ only
■■

Remarks

_splitpatti takes a file's full path name (path) as a string in the form

X:\DIR\SUBDIR\NAME.EXT

and splits path into its four components. It then stores those components in the strings pointed to by drive, dir, name, and ext. (All five components must be passed, but any of them can be a null, which means the corre-sponding component will be parsed but not stored.)

The maximumsizes for these strings are given by the constants
_MAX_DRIVE, _MAX_DIR, _MAX_PATH, _MAX_FNAME,and _MAX_EXT (defined

in stdlib.h), and each size includes space for the null-terminator. These constants are defined in stdlib.h.

ConstantMaxString
MAX PATH(80)path
MAX DRIVE(3)drive; includes colon (:)
_MAX_DIR(66)dir; includes leading and trailing backslashes (\)
MAX FNAME(9)name
_MAX_EXT(5)ext; includes leading dot (.)

_splitpath assumes that there is enough space to store each non-null component.

When _splitpath splits path, it treats the punctuation as follows:

□ drive includes the colon (C:, A:, and so on). G dir includes the leading and trailing backslashes (\BC\include\, \ sourceX, and so on). D na7ne includes the file name. a ext includes the dot preceding the extension (.C, .EXE, and so on).

_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

None.

See also

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)-l]  != '\\')
      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;

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.