文件搜索查找功能VC++
1.搜索指定文件夹下的文件名和路径
#undef UNICODE #include <iostream>
#include <string>
#include <vector>
#include <memory>
#include <cstring> #include <windows.h> std::shared_ptr<std::vector<std::string> > fileList(const std::string& folder_path)
{
static std::shared_ptr<std::vector<std::string> >
folder_files(new std::vector<std::string>); //返回指针, 需要迭代使用 WIN32_FIND_DATA FindData;
HANDLE hError; int file_count();
std::string file_path(folder_path); //路径名
std::string full_file_path; //全路径名 file_path.append("/*.*");
hError = FindFirstFile(file_path.c_str(), &FindData);
if (hError == INVALID_HANDLE_VALUE) {
std::cout << "failed to search files." << std::endl;
return nullptr;
}
while(FindNextFile(hError, &FindData))
{
//过虑".", "..", "-q"
if( == strcmp(FindData.cFileName, ".") ||
== strcmp(FindData.cFileName, "..") ||
== strcmp(FindData.cFileName, "-q"))
{
continue;
} //完整路径
full_file_path.append(folder_path);
full_file_path.append("/");
full_file_path.append(FindData.cFileName);
++file_count; if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY){
//std::cout << file_count << " " << full_file_path << "<Dir>" << std::endl;
fileList(full_file_path);
}else{
folder_files->push_back(full_file_path);
//std::cout << file_count << " " << full_file_path << std::endl;
}
full_file_path.clear(); //清空目录
}
return folder_files;
} int main(void)
{
std::shared_ptr<std::vector<std::string> > folder_files;
folder_files = fileList("E:/bf");
if (folder_files) {
for (size_t i=; i != folder_files->size(); ++i) {
std::cout << i+ << " : " << (*folder_files)[i] << std::endl;
}
}
return ;
}

#include<afx.h>
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
TCHAR filePath[]=L"*.*";
CFileFind finder;
BOOL bFinderResult = finder.FindFile(filePath);
//std::cout << filePath << std::endl;
while (bFinderResult!=false)
{
bFinderResult=finder.FindNextFileW();
CString szRepeter = finder.GetFileName();
//const int iSize = szRepeter.GetLength();
char bufFileName[];
WideCharToMultiByte(, , szRepeter, , bufFileName, , NULL, false);
//fFileName = (LPCTSTR)szRepeter;
std::cout << bufFileName << std::endl;
}
system("pause");
return ;
}
//注意要设置共享MFC中使用.
更多可以参看:http://www.jizhuomi.com/software/340.html
文件搜索查找功能VC++的更多相关文章
- IDEA+控制台使用搜索\查找功能
- Linux如何搜索查找文件里面内容
在Linux系统当中,如何搜.索查找文件里面的内容呢? 这个应该是系统维护.管理当中遇到最常见的需求.那么下面介绍,总结一下如何搜索.查找文件当中的内容. 搜索.查找文件当中的内容,一般最常用的是gr ...
- 有关文件夹与文件的查找,删除等功能 在 os 模块中实现
最近在写的程序频繁地与文件操作打交道,这块比较弱,还好在百度上找到一篇不错的文章,这是原文传送门,我对原文稍做了些改动. 有关文件夹与文件的查找,删除等功能 在 os 模块中实现.使用时需先导入这个模 ...
- IDEA文件查找功能失效(ctrl+shift+N)
由于断电.蓝屏引起的强制关机等情况,会导出IDEA文件查找功能失效,Enter file name窗口输入的文字显示红色,无法查出需要的文件. 解决方法: 可以点击File,选择Invalidate ...
- Linux下文件搜索、查找、查看命令
Linux下文件搜索.查找.查看命令 1.最强大的搜索命令:find 查找各种文件的命令 2.在文件资料中查找文件:locate 3.搜索命令所在的目录及别名信息:which 4.搜索命令所在的目录及 ...
- Xcode编辑器之filter查找功能和查看最近修改的文件
一,前言 有时候,我们的项目过大,创建类过多就会造成“目标文件”不好查找.这时候通过“filter”进行目录结构筛选无疑是最好的选择. 二,什么是filiter filiter 顾名思义为“过滤”,“ ...
- VS2010类似Eclipse文件查找功能-定位到
快捷键:Ctrl + , 打开定位到窗口,可以在文件或类文件中查找内容.
- Linux常用命令学习2---(文件搜索命令locate find、命令搜索命令whereis which、字符串搜索命令grep、帮助命令man)
1.文件搜索命令:locate [文件名] 在后台数据库中按文件名搜索,搜索速度比find快,耗费资源更少 例子:locate test.txt,就会显示文件名包含 test.txt的所 ...
- FindinFiles - Windows文件内查找插件
FindInFiles for Windows 今天分享一个不错的插件工具:FindInFiles.如其名,其功能和Visual Studio的Ctrl+H快捷键类似,方便Windows使用者在资源管 ...
随机推荐
- canvas、image src、data url、blob file conversion
//canvas.toDataURL('image/jpeg'), and convert to blob,blob is a File Object. but UC don't support fu ...
- JQ选择器
jQuery 的选择器可谓之强大无比,这里简单地总结一下常用的元素查找方法 $("#myELement") 选择id值等于myElement的元素,id值不能重复在文档中只能有一个 ...
- JQ 操作样式,单选按钮跟复选框
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Oprofile安装与使用探索
本文分别尝试了oprofile在x86平台和龙芯平台上的安装 一:oprofile的安装与配置(intel+ubuntu12.04) I. Oprofile 安装 Oprofile 包含在 Linux ...
- 【Android类型SDK测试(一)】认识Android类型的 SDK
(一)SDK是个什么东东 接触软件相关行业的同学都应该知道,SDK(即 Software Development Kit),软件开发包.其作用就是为开发某些软件提供一些便利的东西,包括工具 集合,文档 ...
- nginx+webpy 出现 upstream timed out
关于nginx配置webpy应用出现的错误 upstream timed out (: Connection timed out) while reading response header from ...
- AngularJS入门基础PPT(附下载链接)
学习了Angularjs有段时间,自己写了一个PPT,个人认为总结的非常全面,对于入门基础够了. 大致模块有:Angularjs简单介绍,Angularjs特性,hello world,Control ...
- mysql的四种隔离级别
一.READ UNCOMMITTED(未提交读) 在READ UNCOMMITTED级别,事务中的修改,即使未提交,对其他事务也都是可见的.事务可以读取未提交的数据,这也被称为脏读( Dirty RE ...
- Swift笔记4
字符 var str = " hello world " var kong = "" 或者 var kong = string() //定义一个空的字符 ...
- 使用Python管理Azure(1):基础配置
Azure提供了丰富的Python SDK来对Azure进行开发管理,包括使用Azure的开源框架在Azure上创建web应用程序,对Azure的虚拟机,存储等进行管理,本系类会简单介绍如何在ASM和 ...