windows 路徑常用函式使用

2021-10-09 01:56:07 字數 1609 閱讀 2625

char buffer[max_path];

getmodulefilenamea( null, buffer, max_path );

pathremovefilespeca(buffer);

// c: d: 和後邊路徑合併

char cfg_path[max_path];

pathcombinea(cfg_path, buffer, "config.cfg");

char* s = pathfindextensiona(cfg_path);

fmt::print("{}\n", s);

char* s2 = pathfindfilenamea(cfg_path);

fmt::print("{}\n", s2);

char* s3 = pathfindnextcomponenta(cfg_path);

fmt::print("{}\n", s3);

// 普通的路徑增加,注意第乙個引數

char buffer_1[max_path] = "name_1\\name_2";

// 檔案或資料夾是否存在1就代表存在

int ret = pathfileexistsa("d:\\log1.txt");

int ret2 = pathfileexistsa("e:\\vs2010-c++\\fmttest");

得到模組或是exe的執行目錄的函式:

static bool getselfmodulepath(char* path)

; getmodulefilenamea(dllhandle, t_path, max_path);

pathremovefilespeca(t_path);

strcpy_s(path, sizeof(t_path), t_path);

return true;

}static bool getselfmodulepath2(char* path, char* combinfilename)

; getmodulefilenamea(dllhandle, t_path, max_path);

pathremovefilespeca(t_path);

pathcombinea(path, t_path, combinfilename);

return true;

}

呼叫:

char dllpath[max_path] = ;

getselfmodulepath(dllpath);

pathremovefilespeca(dllpath);

char domainpath[max_path] = ;

pathcombinea(domainpath, dllpath, "domain.ini");

char url[256] = ;

getprivateprofilestringa("url", "drdata", "", url, sizeof(url),domainpath);

char abc[256] = ;

getselfmodulepath2(abc, "domain.ini");

windows路徑操作API函式

pathremoveargs 去除路徑的引數 pathremovebackslash 去除路徑最後的反斜槓 pathaddbackslash 在路徑最後加上反斜槓 pathremoveblanks 去除路徑前後的空格 pathaddextension 在檔案路徑後面加上副檔名 pathremovee...

windows路徑操作API函式

windows 路徑操作 api函式 路徑截斷與合併函式 pathremoveargs 去除路徑的引數 pathremovebackslash 去除路徑最後的反斜槓 pathaddbackslash 在路徑最後加上反斜槓 pathremoveblanks 去除路徑前後的空格 pathaddexten...

windows路徑操作API函式

路徑截斷與合併函式 pathremoveargs 去除路徑的引數 pathremovebackslash 去除路徑最後的反斜槓 pathaddbackslash 在路徑最後加上反斜槓 pathremoveblanks 去除路徑前後的空格 pathaddextension 在檔案路徑後面加上副檔名 p...