如何在计算机上搜索文件和文件夹 [英] how to search the computer for files and folders
问题描述
我需要一种方法在计算机上搜索Windows资源管理器之类的文件。我想让我的程序搜索让硬盘c:。我需要它在C:\中搜索文件夹和文件(就像您在c:\中看到的那样),然后,如果用户单击列表中的文件,例如文件夹测试(C:\test),它将进行搜索测试并让用户查看其中的文件/文件夹。
i need a way to search the computer for files like Windows Explorer. i want my program to search lets say hard drive c:. i need it to search C:\ for folders and files (just the ones you could see in c:\ then if the user clicks on a file on the list like the folder test (C:\test) it would search test and let the user see what files/folders are in it.
推荐答案
自从您提到Windows以来,最直接的winapi方法可以通过 FindFirstFile 和 FindNextFile 函数。
Since you mentioned windows, the most straight forward winapi way to do it is with FindFirstFile and FindNextFile functions.
编辑:这是一个示例,向您展示如何枚举目录中的所有文件/文件夹。
edit: Here's an example that shows you how to enumerate all files/folders in a directory.
#include <Windows.h>
#include <iostream>
int main()
{
WIN32_FIND_DATA file;
HANDLE search_handle=FindFirstFile(L"C:\\*",&file);
if (search_handle)
{
do
{
std::wcout << file.cFileName << std::endl;
}while(FindNextFile(search_handle,&file));
FindClose(search_handle);
}
}
这篇关于如何在计算机上搜索文件和文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!