开发者

Traversing a directory tree in C++

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 b开发者_运维百科ack in the day before boost existed so there's got to be a way to do it.


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.


As of the adoption of the C++17 standard there exists a <filesystem> header included in the language that does exactly this. See your compiler's documentation to determine if it's supported.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜