Tadao Iida
/
SD_Filelist
mbed/ARM 活用事例 第3章 SDカードを使ってファイルを操作するプログラムを作る
Diff: main.cpp
- Revision:
- 0:61120c8385d7
diff -r 000000000000 -r 61120c8385d7 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Oct 04 12:57:29 2011 +0000 @@ -0,0 +1,29 @@ +#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); +} \ No newline at end of file