CString CCallSchedulingSystemDlg::GetFilePath(void)
{
HMODULE module = GetModuleHandle(0);
char pFileName[MAX_PATH];
GetModuleFileName(module, pFileName, MAX_PATH);
CString csFullPath(pFileName);
int nPos = csFullPath.ReverseFind( _T(‘\\‘) );
if( nPos < 0 )
return CString("");
else
return csFullPath.Left( nPos );
}
char* CCallSchedulingSystemDlg::EncodeToUTF8(const char* mbcsStr)
{
// 可播放中文路径、英文路径
int wcsLen;
wchar_t* wszString;
int u8Len;
char* szU8;
//预转换,得到所需空间的大小
wcsLen = ::MultiByteToWideChar(CP_ACP, NULL, mbcsStr, strlen(mbcsStr), NULL, 0);
//分配空间要给‘\0‘留个空间,MultiByteToWideChar不会给‘\0‘空间
wszString = new wchar_t[wcsLen + 1];
//转换
::MultiByteToWideChar(CP_ACP, NULL, mbcsStr, strlen(mbcsStr), wszString, wcsLen);
//最后加上‘\0‘
wszString[wcsLen] = ‘\0‘;
/************************************************************************/
/* unicode to UTF8 */
/************************************************************************/
// unicode to UTF8
//预转换,得到所需空间的大小,这次用的函数和上面名字相反
u8Len = ::WideCharToMultiByte(CP_UTF8, NULL, wszString, wcslen(wszString), NULL, 0, NULL, NULL);
//同上,分配空间要给‘\0‘留个空间
//UTF8虽然是Unicode的压缩形式,但也是多字节字符串,所以可以以char的形式保存
szU8 = new char[u8Len + 1];
//转换
//unicode版对应的strlen是wcslen
::WideCharToMultiByte(CP_UTF8, NULL, wszString, wcslen(wszString), szU8, u8Len, NULL, NULL);
//最后加上‘\0‘
szU8[u8Len] = ‘\0‘;
free(wszString);
return szU8;
}
BOOL CCallSchedulingSystemDlg::EmptyDirectory(CString &sPath)
{
CFileFind finder;
CString sWildCard = sPath + "//*.*";
BOOL bFound;
BOOL bWorking = finder.FindFile(sWildCard);
bFound = bWorking;
while (bWorking)
{
bWorking = finder.FindNextFile();
if (finder.IsDots()) continue;
if (finder.IsDirectory())
{
CString s = finder.GetFilePath();
EmptyDirectory(s);
RemoveDirectory(finder.GetFilePath());
continue;
}
_tunlink( finder.GetFilePath() ); // 注意这里用的是_tunlink
}
return bFound;
}
本文出自 “日知其所无” 博客,请务必保留此出处http://shenyantao.blog.51cto.com/1957956/1543253
原文地址:http://shenyantao.blog.51cto.com/1957956/1543253