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:
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?

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