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??
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
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 thedwFileAttributes
field of theWIN32_FIND_DATA
structure 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)
Alternatively, you can use boost::filesystem which will not only give you a clean API, but will also make your code portable on all supported platforms.
I've used this code to read the files in the specified directory.
Take a look at this example from MSDN using
CFileFind
.