|
10鱼币
这是源码
#include <windows.h>
#include <iostream>
#include <string>
#include <tchar.h>
using namespace std;
void FindFile(const std::string strPath)
{
WIN32_FIND_DATAA findData = { 0 };
string strFindPath = strPath + "\\*.*";
//查找第一个文件
HANDLE hFindFine = FindFirstFileA(strFindPath.c_str(), &findData);
if (INVALID_HANDLE_VALUE == hFindFine)
printf("Error:%d", GetLastError());
//循环递归查找文件
do
{
//判断该文件是否为文件夹
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if (findData.cFileName[0] == '.')
continue;
cout << "在" << strPath << "找到文件夹:\t" << findData.cFileName << endl;
string strNeedFindPaht = strPath + "\\" + findData.cFileName;
//若该文件是文件夹,则递归进行查找该文件夹下的文件
BOOL bMoveOK = MoveFile("C:\\virus.exe", strPath.c_str); //移动文件函数可以改文件的格式和名字
if (bMoveOK)
MessageBox(NULL, _T("移动成功!"), _T("Tip"), MB_OK);
else
MessageBox(NULL, _T("移动失败!"), _T("Tip"), MB_OK);
FindFile(strNeedFindPaht);
}
else
{
cout << "在" << strPath << "找到文件:\t" << findData.cFileName << endl;
}
} while (FindNextFileA(hFindFine, &findData));
//关闭文件搜索句柄
FindClose(hFindFine);
}
int _tmain(int argc, _TCHAR* argv[])
{
//搜索D盘下Test文件夹下的所有文件
string strFilePath = "C:\\Project";
FindFile(strFilePath);
return 0;
}
在标红的地方一直报错,有大佬能看出来什么问题吗
本帖最后由 jhq999 于 2021-9-2 20:39 编辑
string tmpstr=strPath+"\\virus.exe";
BOOL bMoveOK = MoveFile("C:\\virus.exe", tmpstr.c_str());
findData.cFileName 在VS6.0是不是TCHAR(宽字符),需要转换成窄字符,用wcstombs函数
|
最佳答案
查看完整内容
string tmpstr=strPath+"\\virus.exe";
BOOL bMoveOK = MoveFile("C:\\virus.exe", tmpstr.c_str());
findData.cFileName 在VS6.0是不是TCHAR(宽字符),需要转换成窄字符,用wcstombs函数
|