To get all file names in directory

Hi All,

Requirement is:
Need to get all file names in given directory.
I found some ways using third party lib - boost but I am don't want to use it.
I want the solution within standard C++.

Please help me to resolve this requirement.
All suggestions are welcome.



Regards,
Akash
Do you have C++17 (when you say standard C++)?
Because there is this -> https://en.cppreference.com/w/cpp/filesystem

Otherwise, your request is impossible. Standard C++ knows nothing about filesystems.

You have to use whatever comes with your platform, be it
https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-findfirstfilea
or the likes of opendir / readdir / closedir
Hi Salem,
Thank you for the reply.

No for C++17.
I am using Visual Studio 2010 and Windows 7.


Visual Studio 2017/2019 have a free edition, Community.

Either will run on Win 7 w/ SP1, and are C++17 compliant.

https://visualstudio.microsoft.com/vs/

If you are going to upgrade from VS 2010 I'd personally recommend 2019 over 2017.

FYI, 2017 or 2019 do take up a largish amount of HD space.

And C++ infrastructure is not installed as part of a default install. You have to manually select it.
Last edited on
I'd like to add that Boost isn’t exactly “third party” — it is largely written and maintained by people close to (or members of) C++’s steering committee.

I would go as far as to say that any serious C++ programmer should have Boost installed, and it is not unreasonable to require your library/program’s users to have it either.
I want the solution within standard C++... I am using Visual Studio 2010


There IS no solution within standard C++ if you're not using C++17.

I'll say that again.

There IS no solution within standard C++ if you're not using C++17.


Your options are:

1) Come up to C++17 and use std::filesystem
2) Use the Win32 API (which is not part of the C++ standard)
3) Use another library (which, again, is not part of the C++ standard - for example, Boost)
Topic archived. No new replies allowed.