1 #include <iostream>
2 #include <Windows.h>
3 #include <Shlwapi.h>
4 #include <tchar.h>
5
6 #pragma comment (lib, "Shlwapi.lib")
7
8 #define count_of(exp) (sizeof(exp) / sizeof(exp[0]))
9
10 int main()
11 {
12 /*
13 FunctionName:GetModuleFileName()
14 Features:获取当前执行文件的绝对路径
15 */
16 WCHAR szFileName[MAX_PATH] = {0};
17 GetModuleFileName(NULL, szFileName, MAX_PATH);
18
19 /*
20 FunctionName:PathRemoveFileSpec()
21 Features:获取当前执行文件的上一级文件的绝对路径
22 */
23 WCHAR szFilePath[MAX_PATH] = { 0 };
24 _stprintf_s(szFilePath, count_of(szFilePath), szFileName);
25 PathRemoveFileSpec(szFilePath);
26
27 /*
28 FunctionName:PathCombine()
29 Features:可以为一个文件拼接一个完整的绝对路径
30 */
31 WCHAR szNewFileName[MAX_PATH] = { 0 };
32 PathCombine(szNewFileName, szFilePath, _T("test.txt"));
33
34 /*
35 FunctionName:PathFileExists()
36 Features:判断一个文件是否存在
37 return:返回FALSE文件不存在;返回TRUE文件存在
38 */
39 if (PathFileExists(szNewFileName))
40 {
41 printf("The file exists\n");
42 }
43 else
44 {
45 printf("The file not exists\n");
46 }
47
48 /*
49 FunctionName:PathFindFileName()
50 Features:获取当前执行文件的名称
51 */
52 PWSTR szCurrentFileName;
53 szCurrentFileName = PathFindFileName(szFileName);
54
55 /*
56 FunctionName:PathAppend()
57 Features:可以为一个文件拼接一个完整的绝对路径
58 */
59 WCHAR szAppendPath[MAX_PATH] = { 0 };
60 _stprintf_s(szAppendPath, count_of(szAppendPath), szFilePath);
61 PathAppend(szAppendPath, _T("test.txt1"));
62
63 /*
64 FunctionName:PathAppend()
65 Features:获取系统的临时目录(Temp)
66 */
67 WCHAR szTempPath[MAX_PATH] = { 0 };
68 GetTempPath(count_of(szTempPath), szTempPath);
69
70 system("pause");
71
72 return 0;
73 }