sharing everything

C/C++ : Get List Files in Directory

I have a problem when want to get list of files in directory or get list of directory and subdirectory using C++. So, I have try to research this problem and get a simple method using dirent library. Please check below code to get list of files in directory or get list of directory and subdirectory using C++.

Create file with name list_file.cpp. Copy code below :

Compile code to get list of files in directory or get list of directory and subdirectory using C++ using command :

if you set listFiles function in second argument to false, we can get only list of files and directory in current directory. Example, the output from my computer is like this (setting argument to false)

But, if you set the second argument to true, we will get list of files and directory in sub directory. I hope this code can help you to get list of files in directory or get list of directory and subdirectory using C++.

My name is Toto Sugito. This is my notes when I try something. Maybe, this is NOT THE BEST SOLUTION for your problems. If you have other method or idea that better with my post, please share in this blog. Thank for visiting my site.

No Comments Yet

Leave a Reply

Your email address will not be published. Required fields are marked *

 

Categories

Bloggers - Meet Millions of Bloggers