// testTmpMfc.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include "testTmpMfc.h"#ifdef _DEBUG#define new DEBUG_NEW#endif#include <string>#include <iostream>#include <afxinet.h>#define _WIN32_WINNT 0x0400#include <windows.h>// 唯一的应用程序对象CWinApp theApp;using namespace std;bool rmdirHelper( std::string dir );int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])...{ WIN32_FIND_DATA FindFileData; //查找文件时要使用的数据结构 HANDLE hFind = INVALID_HANDLE_VALUE; //定义查找句柄 DWORD dwError; string target = "./a/"; cout << "Target Dir: " << target << endl; string file ="./a/*"; hFind = FindFirstFile( file.c_str(), &FindFileData);//使用FindFirstFile函数来开始文件查找 if (hFind == INVALID_HANDLE_VALUE)...{ CreateDirectory( target.c_str(),NULL ); }else...{ cout << "Result: " << rmdirHelper( target ) << endl; } dwError = GetLastError(); if (dwError == ERROR_NO_MORE_FILES)...{ FindClose(hFind); //关闭查找句柄 }else...{ cout << "Find Next File Error: " << dwError << endl; } string exit; cin >> exit; return 0;}bool rmdirHelper(std::string dir)...{ WIN32_FIND_DATA FindFileData; //查找文件时要使用的数据结构 HANDLE hFind = INVALID_HANDLE_VALUE; //定义查找句柄 DWORD dwError; if( dir[dir.size()-1] != '/') dir.append("/"); string searchMark = dir; searchMark.append("*"); hFind = FindFirstFile( searchMark.c_str(), &FindFileData);//使用FindFirstFile函数来开始文件查找 if (hFind == INVALID_HANDLE_VALUE) ...{ return false; } else ...{ //以下是循环使用FindNextFile函数来查找文件 do ...{ //如果找到的是目录 if( ( FindFileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY ) )...{ //如果是"."或者"..",就跳过 if( strcmp( FindFileData.cFileName,"." ) == 0 || strcmp(FindFileData.cFileName,"..") == 0 )...{ continue; //否则就递归调用 } else ...{ string nextDir = dir; nextDir.append("/"); nextDir.append( FindFileData.cFileName ); if( rmdirHelper( nextDir ) == false)...{ cout << "Clear " << nextDir << " fail." << endl; }else...{ RemoveDirectory( nextDir.c_str() ); } } //如果找到的是文件,就删除 }else...{ string delFile = dir; delFile.append( FindFileData.cFileName ); if( DeleteFile( delFile.c_str() ) == false ) cout << "Delete " << delFile << " fail" << endl; } }while( FindNextFile( hFind,&FindFileData ) != 0 ); dwError = GetLastError(); if (dwError == ERROR_NO_MORE_FILES) ...{ FindClose(hFind); //关闭查找句柄 } else ...{ cout << "Find Next File Error: " << dwError << endl; return false; } } return true;}