I want to read all files inside a given folder(path to folder) using FindFirstFile method provide in windows API. Currently I’m only succeeded in reading files inside the given folder. I could not read files inside sub folders. Can anyone help me to do this??
I want to read all files inside a given folder(path to folder) using FindFirstFile
Share
When you call
FindFirstFile/FindNextFile, some of the “files” it returns will actually be directories.You can check if something is a directory or not by looking at the
dwFileAttributesfield of theWIN32_FIND_DATAstructure that gets returned to you.If you find one that is a directory, then you can simply call your file finding function recursively to go into the subfolders.
Note: Make sure to put in a special case for the
.and..psuedo-directories, otherwise your function will recurse into itself and you’ll get a stack overflowHere’s the documentation if you haven’t already found it:
FindFirstFile
WIN32_FIND_DATA
possible values for dwFileAttributes (remember these are all bit flags, so you’ll have to use & to check)