1. _splitpath function
In C or C + + programming, it is often used to get the path of the program or file, compared to the path decomposition and merge processing, _splitpath and _makepath can do this function.
Declaration of a function
void _splitpath (const char *path, Char *drive, Char *dir, Char *fname, char *ext);
function is the decomposition of the path, the complete path to separate you, is a string to split the function.
Parameter table
Parameters |
Description |
Path |
Full path |
Drove |
Optional drive letter, followed by a colon (:) (Disk Driver ":") |
Dir |
Optional directory path, including trailing slash. Remove the drive letter and file name, the middle part of the path |
FName |
Base filename (no extension) (file name) |
Ext |
Optional filename extension, including leading period (.) (file name extension) |
code example
#include <stdlib.h>#include <stdio.h>intMain () {CharPath_buffer[_max_path] ="D:\\soft\\programming\\vmware.exe";CharDrive[_max_drive];CharDir[_max_dir];CharFname[_max_fname];CharExt[_max_ext]; _splitpath (Path_buffer, Drive, dir, fname, ext);printf("drive:%s\n file name:%s\n file type:%s\n", Drive,fname,ext);strcat(Fname,ext);printf("File name with extension:%s\n", fname);return 0;}
The file path for C + + parsing gets the file name and extension