problem in read mp3 multible file and put them in a list

how to read mp3 ID3v1 tags from directory and put them in a list???
You have to open each file and decode the tag.
http://www.id3.org/Developer_Information
but i need to seperate all mp3 from the folder from the other files ...and then to process them by choise of the user
I see. Specify *.mp3 as a wildcard to the directory traversal. You need to build a list of MP3 files, then check out the mp3 tags.

How are you doing your directory traversal? If you're not sure how to do it, what OS are you using?

There's probably an MP3 library to do all this, but I haven't looked. It may be worth looking for an open source library as handling ID3 tags directly can be a little tricky.
well thats the big deal... i have to seperate mp3 files in a list and then check for tags... but i dont know how to scan the directory and separate the mp3 in a list and then to check for the tags...
What OS are you using?
i use windows 7 but i have the ubuntu also
Mmm ... I guess if you want portable code, you could use Boost.

Here's an example that reads .mp3 files from directories specified on the command line:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <boost/filesystem.hpp>
#include <list>
#include <iostream>
#include <string.h>

typedef std::list<std::string> files_t;

size_t parse(boost::filesystem::path path, files_t& files)
{
	size_t count = 0;

	if (!boost::filesystem::exists(path))
		return count;

	if (boost::filesystem::is_regular_file(path))
	{
		static const std::string ext = ".mp3";

		std::string filename = path.string();
		if (filename.size() > ext.size() &&
		    stricmp(filename.c_str() + filename.size() - ext.size(), ext.c_str()) == 0)
		{
			files.push_back(path.string());
			return ++count;
		}
	}

	if (boost::filesystem::is_directory(path))
	{
		for (boost::filesystem::directory_iterator p(path);
		     p != boost::filesystem::directory_iterator();
		     ++p)
		{
			try
			{
				count += parse(p->path(), files);
			}
			catch (const boost::filesystem::filesystem_error &e)
			{
				std::clog << e.what() << std::endl;
			}
		}
	}

	return count;
}

int main(int argc, char* argv[])
{
	files_t files;
	for (int i = 1; i < argc; ++i)
	{
		size_t n = parse(argv[i], files);
		if (n == 0)
			std::cout << "Found no files in \"" << argv[i] << "\"" << std::endl;
	}

	for (files_t::const_iterator p = files.begin(); p != files.end(); ++p)
		std::cout << *p << std::endl;

	return 0;
}
Last edited on
thanks :) thats very helpfull :) i would never do it that alone :)
Topic archived. No new replies allowed.