• Advertisement
Sign in to follow this  

Getting file names + extensions from folder

This topic is 3314 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello ! Is there any way I could obtain the name of the files inside a folder + their extensions ? So I provide the location , the path to the folder and the rest is done automatically. Oh ... I'm using Win32 and C++ . Any input is appreciated.

Share this post


Link to post
Share on other sites
Advertisement
You could use the Boost.Filesystem library, which provides portable filesystem facilities. One of the examples included with the library shows how you can iterate over the contents of a given directory, which is precisely what you want.

Share this post


Link to post
Share on other sites
Quote:
Original post by ArthY303
I'll check that out but I was wondering isn't there any way I can use native Win32
API calls to do this ?

For sure, you can use the Win32 API too. This thread contains code that exemplifies the use of the FindFirstFile() and FindNextFile() functions.

Share this post


Link to post
Share on other sites
Thanks for all the replies !

I managed to get the name of the files I wanted.However , I had a hard time trying to figure out how to input the path of the folder I wanted to look into.

Eventually , I figured it out. This is how it worked :

ex : L"D:\\*" or
L"D:\\*.jpg" searching only for files with a particular extension

Are there any other ways ?

Share this post


Link to post
Share on other sites
Quote:
Original post by ArthY303
Are there any other ways ?

Other ways to do what ? If you need more flexible pattern matching (eg. list all files from a set of multiple extensions), then just read in everything and do the pattern matching yourself on the fly.

Or do you want other ways to read in a directory ? The ultimate way under Windows is IShellFolder. This will let you enumerate any part of the file system, including the virtual parts: desktop, shortcuts, virtual folders, network, favorites, shell extensions (eg. navigating into ZIP or RAR archives), etc. It's extremely flexible, but also very complex to use compared to FindFirst/NextFile.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement