This is been a curiosity of mine for a while: how do you traverse a directory tree without using boost or any third-party library? Just plain ol' C++ (examples in 98, 99, 01, 0x and 1x specs are okay.)? It was done back in the day before boost existed so there's got to be a way to do it.
Directory traversal (also known as file path traversal) is a web security vulnerability that allows an attacker to read arbitrary files on the server that is running an application. This might include application code and data, credentials for back-end systems, and sensitive operating system files.
For example, when listing files in a Windows command prompt, you can use the dir /s command to recursively list all files in the current directory and any subdirectories.
Please take a look at http://en.wikipedia.org/wiki/Dirent.h
The reference also has a link to dirent.h implementation for Windows or you can use cygwin
If you want to just do it for Windows you can build upon this example
http://msdn.microsoft.com/en-us/library/aa365200%28VS.85%29.aspx
There are no standard filesystem functions, so you won't get any answers that use "plain C++". For POSIX systems, opendir is used. For Windows, FindFirstFile. I'm not sure about other OSes.
There's a reason people recommend Boost Filesystem—it's portable and takes care of all these details for you.
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