mbed/ARM 活用事例 第3章 SDカードを使ってファイルを操作するプログラムを作る

Dependencies:   mbed

main.cpp

Committer:
sunifu
Date:
2011-10-04
Revision:
0:61120c8385d7

File content as of revision 0:61120c8385d7:

#include "mbed.h"

LocalFileSystem local("local"); 

int main() {
    DIR *d;
    struct dirent *p;
    FILE *fp;
    int i=1;

    fp = fopen("/local/filelist.txt","w");
    if(fp== NULL) {
        printf("File /local/filelist.txt could not be opened!\r\n");
        exit(1);
    }
    d = opendir("/local");
    
    if (d != NULL) {
        while ((p = readdir(d)) != NULL) {              
            fprintf(fp,"[%d] - %s\r\n",i,p->d_name);
            i++;
        }
    } else {
        printf("Could not open directory!\r\n");
        exit(1);
    }
    closedir(d);
    fclose(fp);
}