LocalFileSystem List file directory?

05 Jun 2010

Has there been any work done on listing file name and information created by the LocalFileSystem? For instance the equivalent of the Linux "ls" command or the MSDOS "dir" command?

My application logs data and stores it on an SD Card. Depending upon the rate of the data being logged, a new file might be created each hour. These are files that the mbed system will create. A remote host periodically will ask for a list of the files currently on the SD card, and then may request download or deletion of some of these files.

On the other side, mbed will have to read an SD Card prepared elsewhere (laptop, etc) for its .INI and configuration file information.

Is this going to be too complex for a stand-alone (non OS) application, or should I be looking at CoCOS or even embedded Linux for the embed module?

Thanks,

Doug Wendelboe

05 Jun 2010

Hi Doug,

The opendir(), readdir() and closedir() functions do what you want. Here is a simple example of using them:

void listdir(void) {
    DIR *d;
    struct dirent *p;

    d = opendir("/sd");
    if (d != NULL) {
        while ((p = readdir(d)) != NULL) {
            printf(" - %s\n", p->d_name);
        }
    } else {
        printf("Could not open directory!\n");
    }
    closedir(d);
}

This snippet is taken from my BoB3Test program which is published on my home page.

Regards,

Paul

05 Jun 2010

Thanks, Paul.

06 Jun 2011

Sorry guys for bumping this, bit I have two questions..

Is it also possible to show directories within local? This also works for SD-cards (for SD-card it also shows directories). But I wonder how to check if it's a file or folder. I've read something about p->d_type == isFile, but the mbed compiler doesn't know d_type.

Any help is appreciated.

Thanks, Rick Willeme

06 Jun 2011

Hi Rick,

You can create folders in the PC's mbed drive, put files in them and access the files ok. However, the folders and files do not appear in the mbed directory listing.

The DOS directory entry appears to have been clobbered. All you can read from mbed is the file name.

Paul

06 Jun 2011

Thanks Paul for your answer. Quite strange that you can't see folders.

Do you also have a solution for my second question? (The d_type thing?)

Thanks!

07 Jun 2011

Sorry, I can't help with your second question.

Paul

13 May 2013

How can i get the

'full'

file name not the dos 8.3 ?

Cheers

Ceri

13 May 2013

Hi Ceri,

According to the official page https://mbed.org/handbook/LocalFileSystem it only supports 8.3 file names...

Warning

The LocalFilesystem has a few restrictions:

Only 8.3 filenames are supported Sub-directories are not supported fseek is not supported for files opened for writing ("w") File access calls (fread, fwrite) will block, including interrupts, as semihosting is effectively a debug breakpoint

It's a shame as it'd be even better if it had a more flexible implementation.

HTH

Jez