码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-01-23 13:23:27      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:

#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;
}

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

标签:

原文地址:http://blog.csdn.net/y601500359/article/details/43053985

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!