DirectoryList library by Okano-san
Fork of DirectoryList by
DirectoryList.cpp@1:0233769f991c, 2015-07-17 (annotated)
- Committer:
- MACRUM
- Date:
- Fri Jul 17 06:05:59 2015 +0000
- Revision:
- 1:0233769f991c
- Parent:
- 0:3cd1685a4c22
Add DirHandle.h inclusion
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okano | 0:3cd1685a4c22 | 1 | /** |
okano | 0:3cd1685a4c22 | 2 | * DirectoryList library |
okano | 0:3cd1685a4c22 | 3 | * |
okano | 0:3cd1685a4c22 | 4 | * @author Tedd OKANO |
okano | 0:3cd1685a4c22 | 5 | * @version 0.1 |
okano | 0:3cd1685a4c22 | 6 | * @date Jan-2015 |
okano | 0:3cd1685a4c22 | 7 | * |
okano | 0:3cd1685a4c22 | 8 | * A simple directory listing interface |
okano | 0:3cd1685a4c22 | 9 | */ |
okano | 0:3cd1685a4c22 | 10 | |
okano | 0:3cd1685a4c22 | 11 | #include "mbed.h" |
okano | 0:3cd1685a4c22 | 12 | #include "DirectoryList.h" |
okano | 0:3cd1685a4c22 | 13 | #include <algorithm> |
okano | 0:3cd1685a4c22 | 14 | |
okano | 0:3cd1685a4c22 | 15 | DirectoryList::DirectoryList( char *path ) : error_flag( NOT_INITIALIZED ) |
okano | 0:3cd1685a4c22 | 16 | { |
okano | 0:3cd1685a4c22 | 17 | init( string( path ) ); |
okano | 0:3cd1685a4c22 | 18 | } |
okano | 0:3cd1685a4c22 | 19 | |
okano | 0:3cd1685a4c22 | 20 | DirectoryList::DirectoryList( std::string path ) : error_flag( NOT_INITIALIZED ) |
okano | 0:3cd1685a4c22 | 21 | { |
okano | 0:3cd1685a4c22 | 22 | init( path ); |
okano | 0:3cd1685a4c22 | 23 | } |
okano | 0:3cd1685a4c22 | 24 | |
okano | 0:3cd1685a4c22 | 25 | void DirectoryList::init( std::string path ) |
okano | 0:3cd1685a4c22 | 26 | { |
okano | 0:3cd1685a4c22 | 27 | DIR *dir; |
okano | 0:3cd1685a4c22 | 28 | struct dirent *dp; |
okano | 0:3cd1685a4c22 | 29 | |
okano | 0:3cd1685a4c22 | 30 | if ( NULL == (dir = opendir( path.c_str() )) ) { |
okano | 0:3cd1685a4c22 | 31 | error_flag = ERROR_AT_FILE_OPEN; |
okano | 0:3cd1685a4c22 | 32 | return; |
okano | 0:3cd1685a4c22 | 33 | } |
okano | 0:3cd1685a4c22 | 34 | |
okano | 0:3cd1685a4c22 | 35 | while ( NULL != (dp = readdir( dir )) ) |
okano | 0:3cd1685a4c22 | 36 | this->push_back( dp->d_name ); |
okano | 0:3cd1685a4c22 | 37 | |
okano | 0:3cd1685a4c22 | 38 | closedir( dir ); |
okano | 0:3cd1685a4c22 | 39 | |
okano | 0:3cd1685a4c22 | 40 | std::sort( this->begin(), this->end() ); |
okano | 0:3cd1685a4c22 | 41 | error_flag = NO_ERROR; |
okano | 0:3cd1685a4c22 | 42 | } |
okano | 0:3cd1685a4c22 | 43 | |
okano | 0:3cd1685a4c22 | 44 | DirectoryList::~DirectoryList() |
okano | 0:3cd1685a4c22 | 45 | { |
okano | 0:3cd1685a4c22 | 46 | } |
okano | 0:3cd1685a4c22 | 47 | |
okano | 0:3cd1685a4c22 | 48 | int DirectoryList::error_check( void ) |
okano | 0:3cd1685a4c22 | 49 | { |
okano | 0:3cd1685a4c22 | 50 | return error_flag; |
okano | 0:3cd1685a4c22 | 51 | } |