About file path character segmentation and combination

 

_splitpath


Header files needed are: <stdlib.h>
function prototype is as follows:

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

Which contains five parameters, the first one is the full file name path to be processed, for example: "c: \ windows \ myfile.txt ", of course, the file name may not be so complete that even "myfile.txt" so the string can be treated successfully.
Back four parameters represent the need for four strings taken from the original file path, with a drive letter (Drive), the middle path (the dir), the file name (fname), and extension (ext).
Simply pass the corresponding string pointers in these four parameters, you can get the corresponding string interception function returns, do not want to get filled NULL can be directly ignored, for example, I just want to intercept file extension, then the function can be called as follows:
_splitpath (path, NULL, NULL, NULL, EXT);

 

_makepath

Function prototype is as follows:

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

Usage and _splitpath similar to the opposite effect.

 
   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", "\\sample\\crt\\", "makepath", "c" );  
   printf( "Path created with _makepath: %s\n\n", path_buffer );  
   _splitpath( path_buffer, drive, dir, fname, ext );  

 

 

Guess you like

Origin www.cnblogs.com/ice-arrow/p/11950004.html