File enumeration?

12 Dec 2011

Sorry guys, maybe I've overseen it. I found everything about opening/reading/writing files and also reading and changing timestamps. But I didn't found anything about how to enumerate all the files on the local flash. How do I do it?

My idea is to enumerate and show all files on a LCD and select the one to execute. Then change the time stamp and reset the mbed. Do you think this idea is good?

13 Dec 2011

If from within the mbed compiler, you expand the mbed library object in your project, you will see a list of all the classes supported by the mbed library. Clicking on LocalFileSystem will bring up its documentation and the sample towards the top of this documentation contains the following example code:

#include "mbed.h"

LocalFileSystem local("local");             // Create the local filesystem under the name "local"

int main() {
    FILE *fp = fopen("/local/out.txt", "w");  // Open "out.txt" on the local file system for writing
    fprintf(fp, "Hello World!");
    fclose(fp);
    remove("/local/out.txt");                 // Removes the file "out.txt" from the local file system

    DIR *d = opendir("/local");               // Opens the root directory of the local file system
    struct dirent *p;
    while((p = readdir(d)) != NULL) {         // Print the names of the files in the local file system
      printf("%s\n", p->d_name);              // to stdout.
    }
    closedir(d);
}

The second half of this example shows how to open the root directory of the LocalFileSystem and lists its contents. Just beware that you can only do that with the root directory on the LocalFileSystem though.

13 Dec 2011

so I've overseen it, thank you very much!

19 Jun 2012

Hi Rene, In your original question you mention "....and also reading and changing timestamps", is this possible?