#include <iostream>
#include <io.h> // _findfirst
#include <io.h> // _findfirst
using namespace std;
int main(int argc, char* argv[])
{
char filespec[BUFSIZ];
struct _finddata_t fileinfo;
intptr_t filehandle;
{
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;
}
{
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;
}