Sample code for DirectoryList class library
Dependencies: DirectoryList mbed
Information
Use of this sample code is described in library page.
https://developer.mbed.org/users/okano/code/DirectoryList/
このサンプルコードの使い方の説明は,ライブラリのページで解説されています. https://developer.mbed.org/users/okano/code/DirectoryList/
main.cpp@2:e1cc05857acb, 2015-07-17 (annotated)
- Committer:
- okano
- Date:
- Fri Jul 17 12:24:47 2015 +0000
- Revision:
- 2:e1cc05857acb
- Parent:
- 0:f31922ea4d33
including updated library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okano | 0:f31922ea4d33 | 1 | /** |
okano | 0:f31922ea4d33 | 2 | * DirectoryList library demo program |
okano | 0:f31922ea4d33 | 3 | * |
okano | 0:f31922ea4d33 | 4 | * @author Tedd OKANO |
okano | 0:f31922ea4d33 | 5 | * @version 0.1 |
okano | 0:f31922ea4d33 | 6 | * @date Jan-2015 |
okano | 0:f31922ea4d33 | 7 | * |
okano | 0:f31922ea4d33 | 8 | * A simple directory listing interface. |
okano | 0:f31922ea4d33 | 9 | */ |
okano | 0:f31922ea4d33 | 10 | |
okano | 0:f31922ea4d33 | 11 | #include "mbed.h" |
okano | 0:f31922ea4d33 | 12 | #include "DirectoryList.h" |
okano | 0:f31922ea4d33 | 13 | |
okano | 0:f31922ea4d33 | 14 | LocalFileSystem local( "local" ); |
okano | 0:f31922ea4d33 | 15 | |
okano | 0:f31922ea4d33 | 16 | int main(void) |
okano | 0:f31922ea4d33 | 17 | { |
okano | 0:f31922ea4d33 | 18 | // |
okano | 0:f31922ea4d33 | 19 | // make an instance and get file name list |
okano | 0:f31922ea4d33 | 20 | // |
okano | 0:f31922ea4d33 | 21 | |
okano | 0:f31922ea4d33 | 22 | DirectoryList dir( "/local" ); |
okano | 0:f31922ea4d33 | 23 | |
okano | 0:f31922ea4d33 | 24 | // |
okano | 0:f31922ea4d33 | 25 | // check if the directory list is obtained successfully |
okano | 0:f31922ea4d33 | 26 | // |
okano | 0:f31922ea4d33 | 27 | |
okano | 0:f31922ea4d33 | 28 | if ( dir.error_check() ) |
okano | 0:f31922ea4d33 | 29 | error( "directory could not be opened\r\n" ); |
okano | 0:f31922ea4d33 | 30 | |
okano | 0:f31922ea4d33 | 31 | // |
okano | 0:f31922ea4d33 | 32 | // show file names |
okano | 0:f31922ea4d33 | 33 | // each file names are given as std::string object |
okano | 0:f31922ea4d33 | 34 | // (call "c_str()" if you need to convert to "char *") |
okano | 0:f31922ea4d33 | 35 | // |
okano | 0:f31922ea4d33 | 36 | // this sample shows the file name displayed by printf |
okano | 0:f31922ea4d33 | 37 | // with converting string class to normal-C-string |
okano | 0:f31922ea4d33 | 38 | // |
okano | 0:f31922ea4d33 | 39 | |
okano | 0:f31922ea4d33 | 40 | for ( int i = 0; i < dir.size(); i++ ) |
okano | 0:f31922ea4d33 | 41 | printf( "%s\r\n", dir[ i ].c_str() ); |
okano | 0:f31922ea4d33 | 42 | } |