c++ 文件遍历
#include <io.h>#include <iostream>
#include <string>
#include <fstream>
#include <windows.h>
#include <time.h>
using namespace std;
const int BUF_LEN = 8096;
stringsRoot = "D:\\lalala";
string sSuffix = "\\*.*";// 后缀
void ProcessDir(string sPath);
#include "FileXor.h"
void main()
{
time_t first,second;
first = time(NULL);
locale loc=locale::global(locale(".936"));
ProcessDir(sRoot);
second = time(NULL);
printf("The difference is: %f seconds",difftime(second,first));
getchar();
}
void ProcessDir(string sPath)
{
int filenum = 0;
struct _finddata_t file;
long hFile, hFileNext;
string sPathLast = sPath + sSuffix; //sPathLast = "c:\test\*.*"
hFile = _findfirst(sPathLast.c_str(), &file);
if(hFile == -1)
{
cout<<"文件不存在."<<endl;
return;
}
hFileNext = _findnext(hFile, &file);
while(_findnext(hFile, &file) == 0)
{
if(file.attrib == _A_SUBDIR)//处理以点 开头的 文件 .svn
{
string sAddPath = sPath;
sAddPath += "\\";
sAddPath += file.name;
//cout<<"目录:"<<sAddPath<<endl;
//_findnext(hFile, &file);
ProcessDir(sAddPath);
}
else
{
string sAddPath = sPath;
sAddPath += "\\";
sAddPath += file.name;
cout<<"需要进行处理的文件::::"<<sAddPath<<endl;
filenum++;
string filename = file.name;
}
}
//cout<<"文件个数是"<<filenum<<endl;
}
页:
[1]