将某驱动器或者文件夹内指定类型的文件列出来。
界面如图:
核心代码如下:
// TODO: 在此添加命令处理程序代码
#ifdef NEED_DIR
CString strDir;
GetDlgItemText(IDC_EDIT_DIR, strDir);
if (!strDir.GetLength())
{
strDir = CMfcStrFile::BrowseDir();
if (strDir.GetLength() > 0)
{
SetDlgItemText(IDC_EDIT_DIR, strDir);
}
else
{
return;
}
}
_tstring sDir = CMfcStrFile::CString2string(strDir);
_conf.vDirPaths.clear();
_conf.vDirPaths.push_back(sDir);
#endif // NEED_DIR
#ifdef NEED_FILE
CString strFile;
GetDlgItemText(IDC_EDIT_FILE, strFile);
if (!strFile.GetLength())
{
strFile = CMfcStrFile::OpenFile();
if (strFile.GetLength() > 0)
{
SetDlgItemText(IDC_EDIT_FILE, strFile);
}
else
{
return;
}
}
_tstring sFile = CMfcStrFile::CString2string(strFile);
_conf.vFilePaths.clear();
_conf.vFilePaths.push_back(sFile);
#endif // NEED_FILE
//获取全路径
_conf.bSubDir = ((CButton*)GetDlgItem(IDC_CHECK_SUBDIR))->GetCheck() == TRUE;
_conf.bFullPath = ((CButton*)GetDlgItem(IDC_CHECK_FULLPATH))->GetCheck() == TRUE;
if (((CButton*)GetDlgItem(IDC_RADIO_SEMICOLON))->GetCheck() == TRUE)
{
_conf.nSepIndex = 1;
}
else
{
_conf.nSepIndex = 0;
}
char cSepStr = _conf.nSepIndex == 1 ? ';' : '\n';
//获取后缀
CComboBox* pCombox = (CComboBox*)GetDlgItem(IDC_COMBO_SUFFIX);
if (pCombox != nullptr)
{
CString strSuffix;
pCombox->GetWindowText(strSuffix);
_conf.vSuffixs.clear();
_conf.vSuffixs.push_back(CMfcStrFile::CString2string(strSuffix));
}
_tstring sSuffix = VectorToString(_conf.vSuffixs);
//测试时间
clock_t start, finish;
double duration;
start = clock();
//开始显示进度
//开始显示进度
CTaskBarProgress tbp(m_hWnd);
CProgressInterface* ppi = &tbp;
ppi->Start();
/*********************************这里增加主程序 开始***************************************/
ppi->OutputInfo("Reading the files!");
std::vector<_tstring> vFiles;
std::string suffix = CStdStr::ws2s(sSuffix);
getFiles(sDir, vFiles, suffix.c_str(), _conf.bSubDir);
//将文件转换
for (auto it = vFiles.begin(); it != vFiles.end(); ++it)
{
if (!_conf.bFullPath)
{
*it = CStdStr::GetNameOfFile(*it);
}
*it += cSepStr;
}
CStdFile::SaveTXTFile(sFile, vFiles);
/*********************************这里增加主程序 结束***************************************/
ppi->End();
FlashWindow(TRUE);
finish = clock();
duration = double(finish - start) / CLOCKS_PER_SEC;
int nMinutes = int(duration / 60);
int nSeconds = (int)duration % 60;
CString strTips;
strTips.Format(_T("%d分%d秒%d毫秒"), nMinutes, nSeconds, (finish - start) % CLOCKS_PER_SEC);
//保存log,当前时间以及耗时
CString strTime, strDate; //获取系统时间
CTime tm = CTime::GetCurrentTime();
strTime = tm.Format("%Y年%m月%d日 %X");
strDate = tm.Format("%Y年%m月%d日");
_tstring sLogLine;
#ifdef NEED_FILE
sLogLine = sFile;
#endif // NEED_FILE
#ifdef NEED_DIR
sLogLine = sDir;
#endif // NEED_DIR
//同时需要文件和文件夹时,记录文件夹
CString strSaveLine = _T("本次耗时:") + strTips + "\t" + CString(sDir.c_str()) + '\n';
//保存日志和配置文件
_tstring strIniPath = GetIniPath();
_tstring strExeDir = CStdStr::GetDirOfFile(strIniPath);
CString strLogPath = CStdStr::AddSlashIfNeeded(strExeDir).c_str() + strDate + ".log";
CStdioFile sStdFile(strLogPath, CFile::modeCreate | CFile::modeNoTruncate | CFile::modeReadWrite);
sStdFile.SeekToEnd();
setlocale(LC_CTYPE, "chs");//设定f
sStdFile.WriteString(strSaveLine);
setlocale(LC_ALL, "C"); //还原区域设定
sStdFile.Close();
WriteIniFile(strIniPath, _conf);
AfxMessageBox(strTips);
CDialogEx::OnOK();
更多的交流,欢迎留言。