- void dfsFolder(string folderPath, ofstream &fout)
- {
- _finddata_t FileInfo;
- string strfind = folderPath + "\\*";
- long Handle = _findfirst(strfind.c_str(), &FileInfo);
- if (Handle == -1L)
- {
- cerr << "can not match the folder path" << endl;
- exit(-1);
- }
- do{
- // 判断是否有子目录
- if (FileInfo.attrib & _A_SUBDIR)
- {
- // 这个语句很重要
- if( (strcmp(FileInfo.name,".") != 0 ) &&(strcmp(FileInfo.name,"..") != 0))
- {
- string newPath = folderPath + "\\" + FileInfo.name;
- dfsFolder(newPath, fout);
- }
- }
- else
- {
- fout << folderPath << "\\" << FileInfo.name << " ";
- }
- }while (_findnext(Handle, &FileInfo) == 0);
来源: http://www.bubuko.com/infodetail-2741979.html