VC++文件比较器(一)

写的程序老是丢,还是记录一下吧

遍历指定文件夹下的所有文件并输出


//程序在调用打开关闭文件程序是老是报关于的_CRT_SECURE_NO_DEPRECATE错

在C++/C编译预处理项中添加了_CRT_SECURE_NO_DEPRECATE,不管用


最后在stdafx.h中定义了两个宏就行了,VS2015

#define _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1



//便利穿入的文件夹将所有文件路径输出
void ReverseDirectory(std::string strPath, std::vector<std::string>& arrFilepath)
{
//传入的文件夹
CFileFind finder;
//const char*转换成LPCTSTR文件
//这里本来获取的是一个文件路径
//根据文件路径找到所在目录
std::string strFilePathG = GetFileDirectory(strPath);
strFilePathG += "*.*";


// = (LPCTSTR)strFilePathG.c_str();
CString strFilePathW;
char* p = const_cast<char*>(strFilePathG.c_str());
//strFilePathW.Format("%s", p);//error C2664: 'void ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t,ATL::ChTraitsCRT<wchar_t>>>::Format(UINT,...)': cannot convert argument 1 from 'const char [3]' to 'const wchar_t *'
strFilePathW = p;
BOOL bResult = finder.FindFile(strFilePathW);


while (bResult)
{
bResult = finder.FindNextFile();
if(finder.IsDots())
continue;
USES_CONVERSION;
if (finder.IsDirectory())
{
CString str = finder.GetFilePath();
std::string strs = W2A(str);
strs += "\\";
ReverseDirectory(strs, arrFilepath);
}
CString strFilePath = finder.GetFilePath();
std::string strFilePaths = W2A(strFilePath);
arrFilepath.push_back(strFilePaths);
}
return;
}

调用这个函数

void CCMPDlg::OnBnClickedOk()
{
//并遍历目录中的文件,存入相应的对话框
//MessageBox(_T("chian"), _T("henebi"), MB_OKCANCEL);
CString strSrcPath;
m_editSrcPath.GetWindowText(strSrcPath);
CString strDisPath;
m_editDisPath.GetWindowText(strDisPath);


//分别遍历文件夹中的内容,存储到不同的内存数组中
USES_CONVERSION;
std::string strSrcPaths = W2A(strSrcPath);
ReverseDirectory(strSrcPaths, m_arrSrcPath);
std::string china = "";
MessageBox(_T("chian"), _T("henebi"), MB_OKCANCEL);
// TODO: Add your control notification handler code here
CDialogEx::OnOK();
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

telllong

你的鼓励是我创作最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值