搜索指定文件夹下的指定文件(只能用于一级目录)

#include <iostream>
#include <io.h>
#include <stdlib.h>   //包含system()函数
#include <string>

using namespace std;

const char *to_search = "F:\pro\VC++ VFW\*.cpp";  //欲查找的文件,支持通配符*

int main()
{
	long handle;  //用于查找的句柄
	string str, filename;    
	_finddata_t fileinto;   //文件信息的结构体
	handle = _findfirst(to_search, &fileinto);  //第一次查找文件
	if(-1 == handle)
		return -1;
	cout << "The Serched file is:" << fileinto.name << endl;   //输出查找到的文件名

	while(!_findnext(handle, &fileinto))  //循环查找其它的文件,直到找完文件为止
	{
		cout << "The Serched file is:" << fileinto.name << endl;   //输出查找到的文件名
	}
	_findclose(handle);   //关闭句柄
	return 0;
}

原文地址:https://www.cnblogs.com/SunkingYang/p/11049227.html