// 路径中"\\" 改成"//"的小操作
void trans(std::string &_str){
std::string::size_type loc = 0;
while ((loc = _str.find('\\', loc)) != std::string::npos) {
_str.erase(loc, 1);
_str.insert(loc, "//");
loc += 2;
}
}
// MFC遍历目录中的目录及文件
void BrowseCurrentAllFile(CString strDir)
{
if (strDir == _T(""))
{
return;
}
else
{
if (strDir.Right(1) != _T("\\"))
strDir += L"\\";
strDir = strDir + _T("*.*");
}
CFileFind finder;
CString strPath;
BOOL bWorking = finder.FindFile(strDir);
while (bWorking)
{
bWorking = finder.FindNextFile();
strPath = finder.GetFilePath();
if (finder.IsDirectory() && !finder.IsDots()) {
BrowseCurrentAllFile(strPath); //递归
}
else if (!finder.IsDirectory() && !finder.IsDots())
{
//strPath就是所要获取的文件路径
//m_List.AddString(strPath);
AfxMessageBox(strPath);
// 先获取除文件名之外的路径
int pos = strPath.ReverseFind('\\');
CString onlyPath = strPath.Left(pos + 1); // pos + 1 ?
AfxMessageBox(onlyPath); // 仅路径
CString onlyname = strPath.Right(strPath.GetLength() - pos - 1); // pos + 1 ?
AfxMessageBox(onlyname); // 仅文件名
}
}
}