what I have to do is recursively get “.mp3” archives from a determined pre-specified directory and its subdirectories. I did not have a problem getting the mp3’s and printing them on console. I am using the ftw function specified in http://www.gnu.org/software/libc/manual/html_node/Working-with-Directory-Trees.html#Working-with-Directory-Trees, its call-back function would look like this:
/* Call-back of ftw function*/
int filter_mp3s(const char *dir_name, const struct stat *status, int typeflag){
if (typeflag == FTW_D){
struct dirent **mp3list;
int num_archives;
int counter;
num_archives = scandir (dir_name, &mp3list, select_mp3_ext, alphasort);
/* print mp3 names */
if (num_archives > 0) for (counter = 0; counter <= num_archives - 1; counter++) printf("%s\n", mp3list[counter]->d_name);
}
return 0;
}
What I really want to do is put the names of the files into a GTK combo-box widget. Problem is, that function returns an int type and the function is not flexible with its parameters so I could “save” in something the entries. In other words, mp3’s are found but I have no idea how I could keep the results in order to load them in the combo-box in other function. I do not want to use global variables…
I’m new into this, thanks in advance for your help.
If the callback doesn’t have a customer argument (usually a void*) which appears to be the case, you will have to put found data into a global variable, which is unfortunate.
If that’s a problem (i.e. you are in a multithreaded environment) you will have to implement your own version of recursive directory traversal using opendir interface. It’s not difficult.