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文字の拡張子)となります.

Revision:
0:3cd1685a4c22
Child:
1:0233769f991c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DirectoryList.h	Fri Jan 23 22:37:38 2015 +0000
@@ -0,0 +1,85 @@
+/**
+ *  DirectoryList library
+ *
+ *  @author  Tedd OKANO
+ *  @version 0.1
+ *  @date    Jan-2015
+ *
+ *  A simple directory listing interface
+ */
+
+#ifndef MBED_DIRECTORY_LIST_H
+#define MBED_DIRECTORY_LIST_H
+
+#include    <vector>
+#include    <string>
+
+/** DirectoryList class
+ *
+ *  Simple interface to get file name list of directory
+ *  which is specified by path.
+ *
+ *  The DirectoryList instance will be an object of "std::vector<std::string>".
+ *  
+ *  This library works on local strage on mbed as well as on USB strage. 
+ *  (It has not been tested on SD yet.)
+ *
+ *  Example:
+ *  @code
+ *  #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() );
+ *  }
+ *  @endcode
+ */
+
+class DirectoryList : public std::vector<std::string>
+{
+    typedef enum {
+        NO_ERROR        = 0,
+        NOT_INITIALIZED,
+        ERROR_AT_FILE_OPEN
+    } ErrorCode;
+
+public:
+
+    /** Create a DirectoryList instance of specified path
+     *
+     * @param path string which tells directory path
+     */
+    DirectoryList( char *path );
+
+    /** Create a DirectoryList instance of specified path
+     *
+     * @param path string which tells directory path
+     */
+    DirectoryList( std::string path );
+    
+    /** Destructor of DirectoryList
+     */
+    ~DirectoryList();
+
+    /** Error check function
+     *  
+     *  @return zero if no error
+     */
+    int error_check( void );
+    
+private:
+
+    void init( std::string path );
+    int error_flag;
+};
+
+#endif  //  MBED_DIRECTORY_LIST_H
\ No newline at end of file