文件搜索查找功能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使用者在资源管 ...
随机推荐
- [Linked List]Reorder List
otal Accepted: 54991 Total Submissions: 252600 Difficulty: Medium Given a singly linked list L: L0→L ...
- Python中安装numpy,scipy,matplotlib安装方法
这个吧,说简单也简单,说难吧我捣鼓了两天才弄出来,真是头发都急白了.其实只要一个网址就搞定了,嘿嘿 http://www.lfd.uci.edu 这里面有你需要的任何东西,当你运行python imp ...
- 测试工具:insure++
CSDN资源:http://www.csdn.net/tag/insure%252B%252B 安装. 1,简介:http://baike.baidu.com/link?url=bCcoWd3xi07 ...
- 一种获取spring环境上下文方法:SpringContextUtil
获得spring里注册Bean的有好几种方法,这里介绍一种比较简单的方法: import org.springframework.beans.BeansException; import org.sp ...
- CentOS6.4 LAMP环境搭建
网上的教程,不能按着抄打进去,这样会打乱你环境放置位置, 会导致配置路径会出问题. 要有一个环境目录优化, 把环境文件都装在/usr/local里面 首先,把安装文件rar都放置在/usr/local ...
- NPOI导出多张图片到Excel
常用NPOI导出数据到excel,但没有试过如何导出图片.NPOI最大的特点就是不依赖于Excel组件,服务端不需要安装Excel.在单元格中插入图片主要是用HSSFClientAnchor对象.他有 ...
- 【应用】Markdown 在线阅读器
前言 一款在线的 Markdown 阅读器,主要用来展示 Markdown 内容.支持 HTML 导出,同时可以方便的添加扩展功能.在这个阅读器的基础又做了一款在线 Github Pages 页面生成 ...
- php 数组 (3) reset() end() count() current() key()
<?php /* count()统计数组中元素的个数 reset() 把数组内部指针移动到数组第一个元素,并返回元素值 end() 把数组内部指针移动到数组最后一个元素,并返回元素值 prev( ...
- Python爬虫实战(4):豆瓣小组话题数据采集—动态网页
1, 引言 注释:上一篇<Python爬虫实战(3):安居客房产经纪人信息采集>,访问的网页是静态网页,有朋友模仿那个实战来采集动态加载豆瓣小组的网页,结果不成功.本篇是针对动态网页的数据 ...
- VS2010中添加dll目录
RT,比如用VS写QT,用qmake生成的项目,需要在项目属性里设置:调试->环境,path=%path%;C:\Qt\4.8.5\bin 这样省的每次都要把一堆dll复制到debug/rele ...