新建一个C++控制台程序,增加对MFC的应用。源代码如下:
// TraverseDir.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <afx.h>#include <iostream>#include <WinBase.h>using namespace std;int _tmain(int argc, _TCHAR* argv[]){DWORD ret;if(SetCurrentDirectory("D:/Software") == TRUE){CFileFind finder;BOOL bWorking = finder.FindFile("*.*");while(bWorking){bWorking = finder.FindNextFile();if(finder.IsDirectory())cout<<"Directory: \t";elsecout<<"File: \t\t";cout<<finder.GetFileName()<<endl;}}else{ret = GetLastError();cout<<"GetLastError() = "<<ret<<endl;}return 0;}
运行结果:
Directory:.Directory:..Directory:DevelopeToolFile: FlashFXP.rarFile: jira_4.0.1.crack.rarDirectory:NormalSoftwareDirectory:OtherSoftwareDirectory:proxool-0.9.1File: proxool-0.9.1.zipFile: spring-tx.jar请按任意键继续. . .