1 #ifndef __PATH_HELPER_H__516BEAA4_9BA9_47f8_A9B1_DF4AC1B98D7A
2 #define __PATH_HELPER_H__516BEAA4_9BA9_47f8_A9B1_DF4AC1B98D7A
6 inline bool PathIsDots(
const CString& strFilePath)
8 return strFilePath == _T(
".") || strFilePath == _T(
"..");
11 inline CString& PathAddBackSlash(CString& strFilePath)
13 if(strFilePath.Right(1) != _T(
'\\'))
14 strFilePath += _T(
"\\");
18 inline CString PathGetFileName(
const CString& strFilePath)
20 int nIndex = strFilePath.ReverseFind(_T(
'\\'));
23 return strFilePath.Mid(nIndex+1);
26 inline CString PathGetFileExtension(
const CString& strFilePath)
28 int nIndex = strFilePath.ReverseFind(_T(
'.'));
31 return strFilePath.Mid(nIndex+1);
34 inline CString PathGetFileTitle(
const CString& strFilePath)
36 CString strFileName(PathGetFileName(strFilePath));
37 if(
false == strFileName.IsEmpty())
39 int nIndex = strFileName.ReverseFind(_T(
'.'));
42 return strFileName.Mid(0, nIndex);
48 inline void PathGetFileTitleAndExtension(
const CString& strFilePath, CString& strFileTitle, CString& strFileExtension)
50 strFileTitle = _T(
"");
51 strFileExtension = _T(
"");
53 CString strFileName(PathGetFileName(strFilePath));
55 if(
false == strFileName.IsEmpty())
57 int nIndex = strFileName.ReverseFind(_T(
'.'));
60 strFileTitle = strFileName.Mid(0, nIndex);
61 strFileExtension = strFileName.Mid(nIndex+1);
64 strFileTitle = strFileName;
68 inline CString PathGetFolder(
const CString& strFilePath)
70 int nIndex = strFilePath.ReverseFind(_T(
'\\'));
73 return strFilePath.Mid(0, nIndex+1);
76 inline void PathGetFolderAndFileName(
const CString& strFilePath, CString& strFolder, CString& strFileName)
78 int nIndex = strFilePath.ReverseFind(_T(
'\\'));
81 strFileName = strFilePath;
82 strFolder = _T(
".\\");
85 strFolder = strFilePath.Mid(0, nIndex+1);
86 strFileName = strFilePath.Mid(nIndex+1);
94 inline CString PathGetRootDir(
const CString& strItemPath)
96 int nIndex = strItemPath.Find(_T(
'\\'));
97 if(nIndex == -1)
return _T(
"");
98 return strItemPath.Mid(0, nIndex+1);
105 bool CreateDirectoryStructure(CString& strDestinationRoot,
const CString& strSourceRoot,
const CString& strTargetItemPath)
107 CString strRelativeTargetDir;
109 if(strTargetItemPath.Find(strSourceRoot) != 0)
110 strRelativeTargetDir = strTargetItemPath;
112 strRelativeTargetDir = strTargetItemPath.Mid(strSourceRoot.GetLength());
114 CString FirstDir = PathGetRootDir(strRelativeTargetDir);
115 while(FirstDir.IsEmpty() ==
false)
117 strDestinationRoot += FirstDir;
118 if(PathFileExists(strDestinationRoot) ==
false)
119 if(!CreateDirectory(strDestinationRoot, NULL))
121 strRelativeTargetDir = strRelativeTargetDir.Mid(FirstDir.GetLength());
122 FirstDir = PathGetRootDir(strRelativeTargetDir);;