LocalFileSystem

06 Aug 2012

Hello

I am new to mbed, Could anybody explain me how LocalFileSytem works?

I don´t undestand why this declarations are similar:

LocalFileSystem local("local"); LocalFileSystem localty("webfs");

What are each part? Could I put anything after LocalFileSystem?

Best Regards

06 Aug 2012

As I understand both of them create instance of LocalFileSystem class. local and localty are names of those objects and You use them when You call methods of those objects like local.anymethod();

But "local" and "webfs" are names which are used in result path as /local/my.txt or /webfs/my.txt. You can change both to match Your "needs".

07 Aug 2012

Thank you, but I have more questions:

This is my code:

#include "mbed.h"
 
LocalFileSystem webfs("webfs");
LocalFileSystem local("local");
 
int main() {
    printf("Hello World!\n\r");
    
    wait(1.0);
    
    printf("Opening File...\n\r"); // Drive should be marked as removed
    FILE *fp1 = fopen("/webfs/test.txt", "w");
    if(!fp1) {
        fprintf(stderr, "File /webfs/test.txt could not be opened!\n\r");
        exit(1);
    }
    
    wait(1.0);
    
    printf("Writing Data...\n\r");    
    fprintf(fp1, "Hello World! File /webfs/test.txt");
    
    wait(1.0);
 
    printf("Closing File...\n\r");
    fclose(fp1);
 
    FILE *fp2 = fopen("/local/test.txt", "w");
    if(!fp2) {
        fprintf(stderr, "File /local/test.txt could not be opened!\n\r");
        exit(1);
    }
    
    wait(1.0);
    
    printf("Writing Data...\n\r");    
    fprintf(fp2, "Hello World! File /local/test.txt");
    
    wait(1.0);
 
    printf("Closing File...\n\r");
    fclose(fp2);
        // Drive should be restored. this is the same as just returning from main
 
        wait(1);
} 

In both cases, mbed opens the same file test.txt and is not possible to create different files in different directories.

If is only possible to create files inside root directory, for what the result path is useful? Which is my mistake?

Best regards,