概述
聲明定義void _splitpath( const char *path, char *drive, char *dir, char *fname, char *ext );
說明分解路徑,把你的完整路徑給分割開來,就是一個對字元串進行分割的函式
參數表path
Full path(完整路徑)
driveOptional drive letter, followed by a colon (:)(磁碟驅動包含:)
dirOptional directory path, including trailing slash. Forward slashes (/ ), backslashes (\ ), or both may be used.(檔案路徑,無論是以“/”,“\”)
fnameBase filename (no extension)(檔案名稱)
extOptional filename extension, including leading period (.)(後綴名)
相關
1、與之相反的為:_makepath,實現生成路徑的功能。
2、FindFirstFile函式:到一個資料夾(包括子資料夾)去搜尋指定檔案。
例子
#include
#include
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", "\\sample\\crt\\", "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:\sample\crt\makepath.c
Path extracted with _splitpath:
Drive: c:
Dir: \sample\crt\
Filename: makepath
Ext: .c
參考資料
1、《MSDN》
2、書庫亞洲(shuku asia)編程頻道
3、書庫亞洲知識中心
擴展閱讀
1、相關領域:c語言 java BASIC Microsoft Visual C++ vc vhdl j2ee linux UML VF asp VB delphi JSP sql perl windows 彙編語言 C SHARP c語言程式設計 html。