本文主要介绍了C++ 遍历某个文件夹下所有文件的方法步骤,分享给大家,主要给自己留个笔记。。
#include#include #include #include #include #include using namespace std; void fileSearch(string path) { long hFile = 0; struct _finddata_t fileInfo; string pathName; if ( ( hFile = _findfirst(pathName.assign(path).append("\*").c_str(), &fileInfo) ) == -1) return ; do { cout << path+"\"+fileInfo.name << endl; if( strcmp(fileInfo.name,"..") && strcmp(fileInfo.name,".") && fileInfo.attrib==_A_SUBDIR ) fileSearch(path+"\"+fileInfo.name); } while ( _findnext(hFile, &fileInfo) == 0 ); _findclose(hFile); return ; } int main() { string path="E:\Git"; fileSearch(path); system("pause"); return 0; }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。



