C++ Windows File Search Recursion


Recursively searching for files on Windows isn't necessarily restricted to the Windows API, however my personal preference is to lean towards it if I'm already using the header (many of my C++ projects are VC++ anyways). In the implementation below, the FindFiles function takes the starting file path where the recursion starts. Additionally the function takes a templated vector, a completely optional feature which I added as part of the project I was working on. When a file is found, its path is passed to the constructor of the template class - in my case an image is loaded using the path it just found.




If the file is a directory, call the funcion on itself again - else add the full file path to a vector. Results are stored as WIN32_FIND_DATA. The data structure has a whole assortment of properties that may help you on your file finding needs. Finally, below is a short snippet using the function.