FS Scan Directory

FS Scan Directory

Home Forums Storage Systems FS Scan Directory

This topic contains 1 reply, has 2 voices, and was last updated by  Matt Gordon 3 years, 6 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #15328

    Josh Ankara

    Does Micrium file system have a function like the ls command for Linux? I need to see whats in a directory.


    Matt Gordon

    Although µC/FS does not offer a function that, with one call, returns a complete list of a folder’s files and subfolders, this behavior is fairly easy to implement with the APIs that are presently available from the software. There are actually two sets of functions that could be used to write code for examining directories’ contents. That’s because users of µC/FS can choose between POSIX-like API calls and proprietary Micrium calls for important file system operations. Thus, the situation on the file system is somewhat similar to that of µC/TCP-IP, which offers both a portable, BSD sockets API, and a Micrium-specific API that is capable of detailed error reporting.

    The POSIX-like functions that developers can use for accessing the contents of directories are fs_opendir() and fs_readdir_r(). Not too surprisingly, fs_opendir(), which accepts a path name as its argument and returns a pointer to a directory (assuming that there are no errors), is used for opening directories, while fs_readdir_r() provides a means of reading individual directory entries. The equivalent Micrium-specific functions are FSDir_Open() and FSDir_Rd().

    Code intended to read every entry in a directory would first need to open that directory—via one of the two APIs reserved for that purpose—and then begin reading entries, through a series of calls to either fs_readdir_r() or FSDir_Rd(). A pseudocode example is provided below. This example omits a few details of the operations involved, but it demonstrates the basic concept. For a lengthier, C-code example, along with information on all of the µC/FS directory functions, you can consult the file system section of Micrium’s documentation site.

    void  AppDirRd (void)
        Open directory;                           /* fs_opendir() or FSDir_Open() */
        Read directory entry;                     /* fs_readdir_r() or FSDir_Rd() */
        while (Directory entry is not null) {
            Log or print current entry;
            Read next entry;                      /* fs_readdir_r() or FSDir_Rd() */
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

View the complete site map