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.
Open File Explorer and navigate to the folder you want to search within. Click in the search field. You should see a list of items from previous searches. Type a character or two, and items from previous searches that match your criteria will appear.
1. Click on the Windows key and type "File Explorer," clicking the top app result that appears. 2. If you know which drive or folder the file you're looking for exists in, choose that location via the Quick Access menu on the left-hand side of the File Explorer screen.
For Windows 10, follow these instructions: Hold the windows key and press "r," type in "cmd" and then press enter, type in "cd ../.." and then press enter, type in "tree" and then press enter. This will usually show all of the files on your hard drive.
File Explorer allows you to use Windows Search Explorer (by default) to help you find and view all of your files or folders in one place.
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);
}
}
This will be OS dependent. The SO question
How can I get a list of files in a directory using C or C++?
handles this problem well. You can download DIRENT here.
Now that you have this, I'd recommend recursively searching for a file with a DFS/BFS algorithm. You can assume the whole directory structure is a tree where each file is a leaf node and each subdirectory is an internal node.
So all you have to do is,
void getFilesFolders(vector<string> & dir_list, const string & folder_name)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With