开发者

How to read the mp3 files in a given folder?

开发者 https://www.devze.com 2022-12-19 06:20 出处:网络
how to read the mp3 files and display those file names using c++ can anyone provid开发者_开发问答e me code for this in C++?Use the boost filesystem library, it\'s a very powerful library that will mee

how to read the mp3 files and display those file names using c++ can anyone provid开发者_开发问答e me code for this in C++?


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


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


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
      }
  }    
}    
0

精彩评论

暂无评论...
验证码 换一张
取 消