Flie遍历文件夹下的文件名

来源:互联网 发布:淘宝卖什么比较好? 编辑:程序博客网 时间:2024/05/17 04:20
#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; 
}
0 0