複製鏈接
請複製以下鏈接發送給好友

splitpath

鎖定
在編程過程中,常常需要獲取程序的路徑,並對路徑進行分解和合並,這時就使用到了_splitpath。同時與之相反的功能函數有:_makepath。與之相關的函數有:FindFirstFile等。
中文名
splitpath
説    明
把你的完整路徑給分割開來
參數表
參數表磁盤驅動包含
相    關
到一個文件夾到一個文件夾

splitpath基本信息

splitpath聲明定義

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

splitpath説明

分解路徑,把你的完整路徑給分割開來,就是一個對字符串進行分割的函數
如果函數參數某一項不需要提取,此項設為NULL即可,_makepath函數同理。

splitpath參數表

path, Full path(完整路徑)
drive , Optional drive letter, followed by a colon (:)(磁盤驅動包含:)
dir, Optional directory path, including trailing slash. Forward slashes (/ ), backslashes (\ ), or both may be used.(文件路徑,無論是以“/”,“\”)
fname, Base filename (no extension)(文件名)
ext , Optional filename extension, including leading period (.)(後綴名)

splitpath相關

1、與之相反的為:_makepath,實現生成路徑的功能。
2、FindFirstFile函數:到一個文件夾(包括子文件夾)去搜索指定文件 。

splitpath例子

#include <stdlib.h>
#include <stdio.h>
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

splitpath參考資料

1、《MSDN》
2、書庫亞洲(shuku asia)編程頻道
3、書庫亞洲知識中心

splitpath擴展閲讀

1、相關領域:c語言 java BASIC Microsoft Visual C++ vc vhdl j2ee linux UML VF asp VB delphi JSP sql perl windows 彙編語言 C SHARP c語言程序設計 html。