how to read the mp3 files and display those file names using c++ can anyone provide me code for this in C++?
-
dirent.h: http://www.opengroup.org/onlinepubs/007908799/xsh/dirent.h.html – Feb 01 '10 at 10:27
-
1Dupe http://stackoverflow.com/questions/306533/how-do-i-get-a-list-of-files-in-a-directory-in-c – Feb 01 '10 at 10:32
-
-1 for show me the code. – Skurmedel Feb 01 '10 at 10:45
3 Answers
Use the boost filesystem library, it's a very powerful library that will meet your needs. The documentation should make it easy for you to write this tiny piece of code yourself: http://www.boost.org/doc/libs/1_31_0/libs/filesystem/doc/index.htm
I just saw that you actually can copy and slightly modify this example: http://www.boost.org/doc/libs/1_31_0/libs/filesystem/example/simple_ls.cpp

- 4,261
- 22
- 24
for a portable implementation you can use boost filesystem library that let you to create an iterator over a directory. take a look at boost doc here http://www.boost.org/doc/libs/1_41_0/libs/filesystem/doc/index.htm
there are also non portable function that works only on windows or on unix, but they work in the same way

- 385
- 2
- 11
Here is a quick answer (nearly complete) using boost.filesystem, adapted from an example of basic_directory_iterator.
void iterate_over_mp3_files( const std::string & path_string )
{
path dir_path(path_string);
if ( exists( dir_path ) )
{
directory_iterator end_itr; // default construction yields past-the-end
for ( directory_iterator itr( dir_path );
itr != end_itr;
++itr )
{
if ( ### ) // test for ".mp3" suffix with itr->leaf()
{
path path_found = itr->path();
// do what you want with it
}
}
}

- 16,798
- 8
- 46
- 66