文件搜索查找功能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使用者在资源管 ...
随机推荐
- java学习——函数
class FunctionDemo { public static void main(String[] args) { System.out.println("Hello World!& ...
- 【IOS学习基础】weak和strong、懒加载、循环引用
一.weak和strong 1.理解 刚开始学UI的时候,对于weak和strong的描述看得最多的就是“由ARC引入,weak相当于OC中的assign,但是weak用于修饰对象,但是他们都不会造成 ...
- CentOS Apache服务器安装与配置
原文地址:http://www.linuxidc.com/Linux/2014-01/95256.htm 一.安装Apache程序,一般有三种安装方式: Apache在centos下httpd1.直接 ...
- Linux内核目录解析~
以前进过一些公司看到一些服务器,把环境搭建都搭建在etc里面,而且都乱套了.在找PHP配置文件和apache的conf文件都难找到, 我们应该大致的了解下linux的文件分布 /etc : 放置系统重 ...
- MySQL入门转载
21分钟 MySQL 入门教程 http://www.cnblogs.com/mr-wid/archive/2013/05/09/3068229.html 目录 一.MySQL的相关概念介绍 二.Wi ...
- python 调用shell或windows命令
目前使用到的有两种方式:os.system()和os.popen() import os os.system('cd e:cjx') #调用后返回执行结果状态 如果想获得返回结果,则使用以下方式: i ...
- Words-specialty
1-100 101-200 community n.社区; 共同体; 社会团体; [生态] 群落 overview n.概观; 总的看法; 回顾,复习 transforming vi.改变,使 ...
- 【Xamarin 挖墙脚系列:Windows 10 一个包罗万象的系统平台】
build2016 结束后,证实了微软之前的各种传言.当然,都是好消息. Windows10 上基本可以运行主流的任意的操作系统. Windows Linux(在内部版本143216中,支持了bash ...
- 切图教程,PS和AI切图方法分享
- 使用高性能xml序列化框架jibx作为spring mvc的xml view
package org.springframework.web.servlet.view.xml; import java.io.ByteArrayOutputStream; import java. ...