Directry file listing class Instance will be a vector of string class which holds the file name of given path.

Dependents:   ika_shouyu_poppoyaki DirectoryList_Hello ika_shouyu_poppoyaki eVY1_SMF_player ... more

Information

日本語版がこのページ下半分にあります!

Japanese version is available lower half of this page.

What is this?

A class to list files of a directory (folder).

When an instance is made, it access to the directory information and keeps the file names as vector of strings.

This class library can be used for any file system which is supported by mbed.

  • LocalFileSystem
  • MSCFileSystem (USB mass storage class)
  • SD card (for the SD card operation, sample code is available.).

How to use?

Very easy to use.

  1. Make a instance with path to the directory
  2. Check error status
  3. The file names are available as vector of strings inside of instance.

#include "mbed.h"
#include "DirectoryList.h"

LocalFileSystem local( "local" );

int main(void)
{
    DirectoryList   dir( "/local" );

    if ( dir.error_check() )
        error( "directory could not be opened\r\n" );

    for ( int i = 0; i < dir.size(); i++ )
        printf( "%s\r\n", dir[ i ].c_str() );
}

Import programDirectoryList_Hello

Sample code for DirectoryList class library

Information

The file names are in 8.3 format (old DOS type file name fomat: 8 characters file name with 3 characters suffix).




これはナニ?

ディレクトリ(フォルダ)のリスト・クラスです

このインスタンスが作られるとき,ディレクトリの情報にアクセスしファイル名を文字列のベクタとして保持します.

このクラス・ライブラリは,mbedがサポートしているファイル・システムであれば,そのどれにも使うことができます. This class can be used for any file system which is supported by mbed.

  • LocalFileSystem
  • MSCFileSystem (USBマスストレージ・クラス)
  • SD card (SDカード操作のサンプルコードも用意されています.).

どうやって使う?

とても簡単に使うことができます.

  1. ディレクトリのパスを指定してインスタンスを作る
  2. エラーが起きなかったかチェック
  3. インスタンス内部にファイル名のリストがStringsのベクタとして保持されます

#include "mbed.h"
#include "DirectoryList.h"

LocalFileSystem local( "local" );

int main(void)
{
    DirectoryList   dir( "/local" );

    if ( dir.error_check() )
        error( "directory could not be opened\r\n" );

    for ( int i = 0; i < dir.size(); i++ )
        printf( "%s\r\n", dir[ i ].c_str() );
}

Import programDirectoryList_Hello

Sample code for DirectoryList class library

Information

ファイル名は8.3フォーマット(古いDOS形式のファイル名フォーマット: 8文字のファイル名+3文字の拡張子)となります.

Committer:
okano
Date:
Fri Jan 23 22:37:38 2015 +0000
Revision:
0:3cd1685a4c22
Child:
1:0233769f991c
Initial version

Who changed what in which revision?

UserRevisionLine numberNew 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 #ifndef MBED_DIRECTORY_LIST_H
okano 0:3cd1685a4c22 12 #define MBED_DIRECTORY_LIST_H
okano 0:3cd1685a4c22 13
okano 0:3cd1685a4c22 14 #include <vector>
okano 0:3cd1685a4c22 15 #include <string>
okano 0:3cd1685a4c22 16
okano 0:3cd1685a4c22 17 /** DirectoryList class
okano 0:3cd1685a4c22 18 *
okano 0:3cd1685a4c22 19 * Simple interface to get file name list of directory
okano 0:3cd1685a4c22 20 * which is specified by path.
okano 0:3cd1685a4c22 21 *
okano 0:3cd1685a4c22 22 * The DirectoryList instance will be an object of "std::vector<std::string>".
okano 0:3cd1685a4c22 23 *
okano 0:3cd1685a4c22 24 * This library works on local strage on mbed as well as on USB strage.
okano 0:3cd1685a4c22 25 * (It has not been tested on SD yet.)
okano 0:3cd1685a4c22 26 *
okano 0:3cd1685a4c22 27 * Example:
okano 0:3cd1685a4c22 28 * @code
okano 0:3cd1685a4c22 29 * #include "mbed.h"
okano 0:3cd1685a4c22 30 * #include "DirectoryList.h"
okano 0:3cd1685a4c22 31 *
okano 0:3cd1685a4c22 32 * LocalFileSystem local( "local" );
okano 0:3cd1685a4c22 33 *
okano 0:3cd1685a4c22 34 * int main(void)
okano 0:3cd1685a4c22 35 * {
okano 0:3cd1685a4c22 36 * DirectoryList dir( "/local" );
okano 0:3cd1685a4c22 37 *
okano 0:3cd1685a4c22 38 * if ( dir.error_check() )
okano 0:3cd1685a4c22 39 * error( "directory could not be opened\r\n" );
okano 0:3cd1685a4c22 40 *
okano 0:3cd1685a4c22 41 * for ( int i = 0; i < dir.size(); i++ )
okano 0:3cd1685a4c22 42 * printf( "%s\r\n", dir[ i ].c_str() );
okano 0:3cd1685a4c22 43 * }
okano 0:3cd1685a4c22 44 * @endcode
okano 0:3cd1685a4c22 45 */
okano 0:3cd1685a4c22 46
okano 0:3cd1685a4c22 47 class DirectoryList : public std::vector<std::string>
okano 0:3cd1685a4c22 48 {
okano 0:3cd1685a4c22 49 typedef enum {
okano 0:3cd1685a4c22 50 NO_ERROR = 0,
okano 0:3cd1685a4c22 51 NOT_INITIALIZED,
okano 0:3cd1685a4c22 52 ERROR_AT_FILE_OPEN
okano 0:3cd1685a4c22 53 } ErrorCode;
okano 0:3cd1685a4c22 54
okano 0:3cd1685a4c22 55 public:
okano 0:3cd1685a4c22 56
okano 0:3cd1685a4c22 57 /** Create a DirectoryList instance of specified path
okano 0:3cd1685a4c22 58 *
okano 0:3cd1685a4c22 59 * @param path string which tells directory path
okano 0:3cd1685a4c22 60 */
okano 0:3cd1685a4c22 61 DirectoryList( char *path );
okano 0:3cd1685a4c22 62
okano 0:3cd1685a4c22 63 /** Create a DirectoryList instance of specified path
okano 0:3cd1685a4c22 64 *
okano 0:3cd1685a4c22 65 * @param path string which tells directory path
okano 0:3cd1685a4c22 66 */
okano 0:3cd1685a4c22 67 DirectoryList( std::string path );
okano 0:3cd1685a4c22 68
okano 0:3cd1685a4c22 69 /** Destructor of DirectoryList
okano 0:3cd1685a4c22 70 */
okano 0:3cd1685a4c22 71 ~DirectoryList();
okano 0:3cd1685a4c22 72
okano 0:3cd1685a4c22 73 /** Error check function
okano 0:3cd1685a4c22 74 *
okano 0:3cd1685a4c22 75 * @return zero if no error
okano 0:3cd1685a4c22 76 */
okano 0:3cd1685a4c22 77 int error_check( void );
okano 0:3cd1685a4c22 78
okano 0:3cd1685a4c22 79 private:
okano 0:3cd1685a4c22 80
okano 0:3cd1685a4c22 81 void init( std::string path );
okano 0:3cd1685a4c22 82 int error_flag;
okano 0:3cd1685a4c22 83 };
okano 0:3cd1685a4c22 84
okano 0:3cd1685a4c22 85 #endif // MBED_DIRECTORY_LIST_H