How can I get filenames in directory?

What I want is to get the list of filenames in a directory. I'm using windows. Apparently system("dir") shows the list of files. But I don't need to show them, just get them in a string array. How can I do this?
Hello Rakib771,

The first question is what IDE are you using and do you know what C++ standard the compiler is using?

In C++14 you have "experimental/filesystem" and in C++17 just "filesystem". Not familiar with these, so I do not know if this will do what you want.

Another option system("dir | fileName.txt") will send the output if "dir" to a file that you can read and work with.

Andy
Hello Rakib771,

My apologies. It has been awhile and I thought the pipe was the proper character. turns out it is ">".

After testing this may work for you.system("dir /B > fileName.txt"). This listed just the file names in the directory.

Andy
Thanks a lot Handy Andy.
Topic archived. No new replies allowed.