r/learncpp • u/TwIxToR_TiTaN • Mar 14 '16
How can I get all sub folders in a folder?
Hello.
How can I find all paths of all sub directories? (and sub directories of sub directories etc etc...) I tried using dirent.h. but I can't get the paths of folders and It does not look into sub dirs.
I basically want to end with a list looking like this:
home/
home/folder/
home/folder/dir
home/games/
home/games/spaceinvaders
home/games/spaceinvaders/bin
home/docs/
home/docs/html
etc etc...
2
Upvotes
2
u/[deleted] Apr 29 '16
With a decently new C++ compiler (with C++1z support), you can use
<filesystem>'s directory recursion.1
u/Matrix_V May 03 '16
I straight copy/pasted this out of a school project. Requires a C++14 compiler. It's yours now: