文件搜索查找功能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使用者在资源管 ...
随机推荐
- EF Code Frist
EF:学习资料 http://www.cnblogs.com/libingql/category/366833.html
- Oracle 中的Userenv()
1.USEREVN() 返回当前用户环境的信息,opt可以是:ENTRYID,SESSIONID,TERMINAL,ISDBA,LABLE,LANGUAGE,CLIENT_INFO,LANG,VSIZ ...
- NSString 字符串操作
//一.NSString /*----------------创建字符串的方法----------------*/ //1.创建常量字符串. NSString *astring = @"Th ...
- Plugin is too old, please update to a more recent version, or set ANDROID_DAILY_OVERRIDE environment variable to “*****”
Plugin is too old, please update to a more recent version, or set ANDROID_DAILY_OVERRIDE environment ...
- 学习《Javascript权威指南》的第二章笔记
1.Javascript区分大小写,但是HTML不区分大小写 2.JS会忽略标识之间的空格,多数情况下也会忽视换行符,所以要采用 整齐.一致的编码风格 3.//用作结尾的注释,/* 和 */可以当跨行 ...
- wampserver 2.2装好后80端口未被占用,却打不开localhost
在windows server 2003中装好wampserver2.2后打不开localhost,点击服务全部启动(颜色是橙色)也是打不开,我解决的原因是:安装mysql中sevice中的安装测试服 ...
- 【转】aiohttp 源码解析之 request 的处理过程
[转自 太阳尚远的博客:http://blog.yeqianfeng.me/2016/04/01/python-yield-expression/] 使用过 python 的 aiohttp 第三方库 ...
- SAR数据下载网站
1] http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.144.2153&rep=rep1&type=pdf[2] ht ...
- HTML5 页面制作工具
https://www.zhihu.com/question/30087283 HTML5 页面制作工具 免费的基于 HTML 5 的 Web Apps 生成器工具网站 81 235 初页 制 ...
- poj1163 dp入门
The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 36811 Accepted: 22048 De ...