-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC_PATH.CPP
More file actions
185 lines (162 loc) · 4.65 KB
/
Copy pathC_PATH.CPP
File metadata and controls
185 lines (162 loc) · 4.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
////////////////////////////////////////////////////////////////////////
//
// FileName: c_path.cpp
//
// ファイル、ディレクトリパス操作用
//
//
//制作日 01/02/01
//修正日 06/07/11
//
// 2001 RyusukeHotta
#define _CRT_SECURE_NO_DEPRECATE
#include <windows.h>
#include <shlobj.h>
#include <mbstring.h>
#include <tchar.h>
#include "c_path.h"
/*##############################################################################
CLASS CPath
##############################################################################*/
/*********************************************************
* CPath()
* コントラクタ
*********************************************************/
CPath::CPath(){
;
}
/*********************************************************
* GetExecutePath()
* 実行ディレクトリを得る
*********************************************************/
TCHAR* CPath::GetExecutePath(LPTSTR lpPathname,DWORD nSize){
GetModuleFileName(NULL,lpPathname,nSize);
this->CutFileName(lpPathname);
return lpPathname;
}
/*********************************************************
* GetFullPath()
* 実行ディレクトリに任意ファイルを付け足したパスを得る
*********************************************************/
TCHAR* CPath::GetFullPath(LPTSTR lpPath,DWORD nSize,const LPTSTR lpFilename){
this->GetExecutePath(lpPath,nSize - _tcslen (lpFilename) -10);
if(lpPath[_tcslen (lpPath)-1] != _T('\\')) _tcscat(lpPath,_T("\\"));
_tcscat(lpPath,lpFilename);
return lpPath;
}
/*********************************************************
* GetSpecialFolderFullPath()
* 指定特殊フォルダにファイル名を足したものを求める
* MAX_PATH+ファイル名以上を指定すること
*********************************************************/
TCHAR* CPath::GetSpecialFolderFullPath(LPTSTR lpPath,DWORD nSize,
int iFolder,
const LPTSTR lpFilename)
{
SHGetSpecialFolderPath(NULL,lpPath,iFolder,TRUE);
if(lpPath[_tcslen (lpPath)-1] != _T('\\')) _tcscat(lpPath,_T("\\"));
_tcscat(lpPath,lpFilename);
return lpPath;
}
/*********************************************************
* CutFileName()
* パスからファイル名を取り除く
* cPathChar = ディレクトリ文字列=\
*********************************************************/
void CPath::CutFileName(TCHAR *lpPath,const TCHAR cPathChar){
TCHAR *lpEnd=lpPath;
while(lpPath[0]){
#ifndef _UNICODE
//2バイト文字の先頭はスキップ
if(IsDBCSLeadByte(*lpPath) == 0){
#endif
if((*lpPath == cPathChar)){
lpEnd=lpPath+1;
}
#ifndef _UNICODE
}
#endif
lpPath=CharNext(lpPath);
}
//パス名にファイルを含まなかった場合何もしない
if(lpEnd == lpPath) return;
*lpEnd= _T('\0');
return;
}
/*********************************************************
* GetFilename()
* パスからファイル名の位置のポインタを取得する
* cPathChar = ディレクトリ文字列=\
*********************************************************/
TCHAR* CPath::GetFilename(TCHAR *lpPath,const TCHAR cPathChar){
TCHAR *lpEnd=lpPath;
while(lpPath[0]){
#ifndef _UNICODE
//2バイト文字の先頭はスキップ
if(IsDBCSLeadByte(*lpPath) == 0){
#endif
if((*lpPath == cPathChar)){
lpEnd=lpPath+1;
}
#ifndef _UNICODE
}
#endif
lpPath=CharNext(lpPath);
}
//パス名にファイルを含まなかった場合何もしない
if(lpEnd == lpPath) return NULL;
return lpEnd;
}
/*********************************************************
* CutExt()
* パスまたはファイル名から拡張子を取り除く
*********************************************************/
TCHAR* CPath::CutExt(TCHAR* lpszPath){
TCHAR *pLpoint = lpszPath;
pLpoint +=_tcslen (lpszPath);
pLpoint--;
while(pLpoint[0] && (pLpoint >= lpszPath) ){
pLpoint--;
if(pLpoint[0] == _T('.')){
pLpoint[0] = _T('\0');
return pLpoint+1;
break;
}
}
return NULL;
}
/*********************************************************
* CutExt()
* パスまたはファイル名から拡張子を取り除く
*********************************************************/
TCHAR* CPath::GetExt(TCHAR* lpszPath){
TCHAR *pLpoint = lpszPath;
pLpoint +=_tcslen (lpszPath);
pLpoint--;
while(pLpoint[0]){
pLpoint--;
if(pLpoint[0] == _T('.')){
return pLpoint+1;
break;
}
}
return NULL;
}
BOOL IsExistFile(LPCTSTR lpszFileName, BOOL fDirectory)
{
WIN32_FIND_DATA ffd;
HANDLE hFindFile = FindFirstFile(lpszFileName, &ffd);
if (hFindFile != INVALID_HANDLE_VALUE)
{
FindClose(hFindFile);
// ディレクトリ
if ( fDirectory &&
(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
return TRUE;
// ファイル
if ( !fDirectory &&
!(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
return TRUE;
}
return FALSE;
}