How can I list the files on a disk?

22 Jul 2009 . Edited: 22 Jul 2009

Hi

I'm building an MP3 Player with the MBED and would like to know how I can read the files on my data storage device (1GB Transcend SDMicro Card). How could I do this?

Thanks DW

22 Jul 2009 . Edited: 22 Jul 2009

Hi Daniel,

Here is an example for the local mbed filesystem:

// example to list files in a directory, sford

#include "mbed.h"

LocalFileSystem local("local");

int main() {

	printf("List of files in /local\n");

	DIR *d;
	struct dirent *p;
	d = opendir("/local");
    if(d != NULL) {
        while((p = readdir(d)) != NULL) {
        	printf(" - %s\n", p->d_name);
        }
    } else {
    	error("Could not open directory!");
    }
}

Probably best to check you can get this working first, then try the same on the SDCard filesystem.

Simon