DirectoryList library test program for SD card operation

Dependencies:   DirectoryList SDFileSystem mbed

Just a sample code of DirectoryList library works with SDFilesystem.
/media/uploads/okano/---------_2015-06-04_10.28.47.png

Committer:
okano
Date:
Thu Jun 04 01:27:15 2015 +0000
Revision:
0:6c4b536215c2
initial version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
okano 0:6c4b536215c2 1 #include "mbed.h"
okano 0:6c4b536215c2 2 #include "SDFileSystem.h"
okano 0:6c4b536215c2 3 #include "DirectoryList.h"
okano 0:6c4b536215c2 4
okano 0:6c4b536215c2 5 SDFileSystem sd( p5, p6, p7, p8, "sd" );
okano 0:6c4b536215c2 6
okano 0:6c4b536215c2 7 #define TARGET_DIRECTORY "/sd/DCIM/100D3100"
okano 0:6c4b536215c2 8
okano 0:6c4b536215c2 9 int main(void)
okano 0:6c4b536215c2 10 {
okano 0:6c4b536215c2 11 printf( "\r\n == DirectryList test with SDFileSystem ==\r\n" );
okano 0:6c4b536215c2 12 printf( "accessing to \"%s\"\r\n", TARGET_DIRECTORY );
okano 0:6c4b536215c2 13 //
okano 0:6c4b536215c2 14 // make an instance and get file name list
okano 0:6c4b536215c2 15 //
okano 0:6c4b536215c2 16
okano 0:6c4b536215c2 17 DirectoryList dir( TARGET_DIRECTORY );
okano 0:6c4b536215c2 18
okano 0:6c4b536215c2 19 //
okano 0:6c4b536215c2 20 // check if the directory list is obtained successfully
okano 0:6c4b536215c2 21 //
okano 0:6c4b536215c2 22
okano 0:6c4b536215c2 23 if ( dir.error_check() )
okano 0:6c4b536215c2 24 error( "directory could not be opened\r\n" );
okano 0:6c4b536215c2 25
okano 0:6c4b536215c2 26 //
okano 0:6c4b536215c2 27 // show file names
okano 0:6c4b536215c2 28 // each file names are given as std::string object
okano 0:6c4b536215c2 29 // (call "c_str()" if you need to convert to "char *")
okano 0:6c4b536215c2 30 //
okano 0:6c4b536215c2 31 // this sample shows the file name displayed by printf
okano 0:6c4b536215c2 32 // with converting string class to normal-C-string
okano 0:6c4b536215c2 33 //
okano 0:6c4b536215c2 34
okano 0:6c4b536215c2 35 for ( int i = 0; i < dir.size(); i++ )
okano 0:6c4b536215c2 36 printf( "%s\r\n", dir[ i ].c_str() );
okano 0:6c4b536215c2 37 }