Flie遍歷文件夾下的文件名

#include <iostream> 
#include <io.h> // _findfirst
using namespace std;
int main(int argc, char* argv[]) 

char filespec[BUFSIZ]; 
struct _finddata_t fileinfo; 
intptr_t filehandle;
if (argc == 1) 

cout << "Usage: " << argv[0] << " directory" << endl; 
exit(0); 

sprintf(filespec, "%s\\*.txt", argv[1]); // 指定查找的目錄下的文本文件*.txt 
filehandle = _findfirst(filespec, &fileinfo); 
if (filehandle != -1) 

do 

cout << fileinfo.name << endl; // 輸出文件名 
} while(_findnext(filehandle, &fileinfo) != -1); // 遍歷此目錄下所有文件 
_findclose(filehandle); 

return 0; 
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章