Tadao Iida
/
SD_Filelist
mbed/ARM 活用事例 第3章 SDカードを使ってファイルを操作するプログラムを作る
main.cpp@0:61120c8385d7, 2011-10-04 (annotated)
- Committer:
- sunifu
- Date:
- Tue Oct 04 12:57:29 2011 +0000
- Revision:
- 0:61120c8385d7
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sunifu | 0:61120c8385d7 | 1 | #include "mbed.h" |
sunifu | 0:61120c8385d7 | 2 | |
sunifu | 0:61120c8385d7 | 3 | LocalFileSystem local("local"); |
sunifu | 0:61120c8385d7 | 4 | |
sunifu | 0:61120c8385d7 | 5 | int main() { |
sunifu | 0:61120c8385d7 | 6 | DIR *d; |
sunifu | 0:61120c8385d7 | 7 | struct dirent *p; |
sunifu | 0:61120c8385d7 | 8 | FILE *fp; |
sunifu | 0:61120c8385d7 | 9 | int i=1; |
sunifu | 0:61120c8385d7 | 10 | |
sunifu | 0:61120c8385d7 | 11 | fp = fopen("/local/filelist.txt","w"); |
sunifu | 0:61120c8385d7 | 12 | if(fp== NULL) { |
sunifu | 0:61120c8385d7 | 13 | printf("File /local/filelist.txt could not be opened!\r\n"); |
sunifu | 0:61120c8385d7 | 14 | exit(1); |
sunifu | 0:61120c8385d7 | 15 | } |
sunifu | 0:61120c8385d7 | 16 | d = opendir("/local"); |
sunifu | 0:61120c8385d7 | 17 | |
sunifu | 0:61120c8385d7 | 18 | if (d != NULL) { |
sunifu | 0:61120c8385d7 | 19 | while ((p = readdir(d)) != NULL) { |
sunifu | 0:61120c8385d7 | 20 | fprintf(fp,"[%d] - %s\r\n",i,p->d_name); |
sunifu | 0:61120c8385d7 | 21 | i++; |
sunifu | 0:61120c8385d7 | 22 | } |
sunifu | 0:61120c8385d7 | 23 | } else { |
sunifu | 0:61120c8385d7 | 24 | printf("Could not open directory!\r\n"); |
sunifu | 0:61120c8385d7 | 25 | exit(1); |
sunifu | 0:61120c8385d7 | 26 | } |
sunifu | 0:61120c8385d7 | 27 | closedir(d); |
sunifu | 0:61120c8385d7 | 28 | fclose(fp); |
sunifu | 0:61120c8385d7 | 29 | } |