X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/blobdiff_plain/7b78a5a287827db9e9b16286f3604aef69b37c5c..70702af1370e44e32fb2c3c507e4759a187b4fe5:/fatfs/doc/en/readdir.html diff --git a/fatfs/doc/en/readdir.html b/fatfs/doc/en/readdir.html index bf83ebe..235beee 100644 --- a/fatfs/doc/en/readdir.html +++ b/fatfs/doc/en/readdir.html @@ -13,7 +13,7 @@

f_readdir

-

The f_readdir function reads directory entries.

+

The f_readdir function reads an item of the directory.

 FRESULT f_readdir (
   DIR* dp,      /* [IN] Directory object */
@@ -26,9 +26,9 @@ FRESULT f_readdir (
 

Parameters

dp
-
Pointer to the open directory object.
+
Pointer to the open directory object or null pointer.
fno
-
Pointer to the file information structure to store the read item.
+
Pointer to the file information structure to store the information about read item.
@@ -39,7 +39,6 @@ FRESULT f_readdir ( FR_OK, FR_DISK_ERR, FR_INT_ERR, -FR_NOT_READY, FR_INVALID_OBJECT, FR_TIMEOUT, FR_NOT_ENOUGH_CORE @@ -49,14 +48,14 @@ FRESULT f_readdir (

Description

-

The f_readdir() function reads directory items, file and directory, in sequence. All items in the directory can be read by calling f_readdir() function repeatedly. When relative path feature is enabled (_FS_RPATH >= 1), dot entries ("." and "..") are not filtered out and they will appear in the read items. When all directory items have been read and no item to read, a null string is returned into the fname[] without any error. When a null pointer is given to the fno, the read index of the directory object is rewinded.

-

When LFN feature is enabled, lfname and lfsize in the file information structure must be initialized with valid value prior to use it. The lfname is a pointer to the LFN read buffer. The lfsize is size of the LFN read buffer in unit of TCHAR. If the LFN is not needed, set a null pointer to the lfname and the LFN is not returned. A null string will be returned into the LFN read buffer in case of following conditions.

+

The f_readdir function reads a directory item, informations about the object. All items in the directory can be read in sequence by f_readdir function calls. Dot entries ("." and "..") in the sub-directory are filtered out and they will never appear in the read items. When all directory items have been read and no item to read, a nul string is stored into the fno->fname[] without any error. When a null pointer is given to the fno, the read index of the directory object is rewinded.

+

When support of long file name (LFN) is enabled, a member altname[] is defined in the file information structure to store the short file name of the object. In case of the some conditions listed below, short file name is stored into the fname[] and altname[] has a null string.

-

When the directory item has no LFN information, lower case characters can be contained in the fname[].

+

There is a problem on reading a directory of exFAT volume. The exFAT does not support short file name. This means no name can be returned on the condition above. If it is the case, a "?" is returned as file name to indicate that the object is not accessible. To avoid this problem, configure FatFs _LFN_UNICODE = 1 and _MAX_LFN = 255 to support the full feature of LFN specification.

@@ -70,40 +69,28 @@ FRESULT f_readdir (

Sample Code

 FRESULT scan_files (
-    char* path        /* Start node to be scanned (also used as work area) */
+    char* path        /* Start node to be scanned (***also used as work area***) */
 )
 {
     FRESULT res;
-    FILINFO fno;
     DIR dir;
-    int i;
-    char *fn;   /* This function assumes non-Unicode configuration */
-#if _USE_LFN
-    static char lfn[_MAX_LFN + 1];   /* Buffer to store the LFN */
-    fno.lfname = lfn;
-    fno.lfsize = sizeof lfn;
-#endif
+    UINT i;
+    static FILINFO fno;
 
 
     res = f_opendir(&dir, path);                       /* Open the directory */
     if (res == FR_OK) {
-        i = strlen(path);
         for (;;) {
             res = f_readdir(&dir, &fno);                   /* Read a directory item */
             if (res != FR_OK || fno.fname[0] == 0) break;  /* Break on error or end of dir */
-            if (fno.fname[0] == '.') continue;             /* Ignore dot entry */
-#if _USE_LFN
-            fn = *fno.lfname ? fno.lfname : fno.fname;
-#else
-            fn = fno.fname;
-#endif
             if (fno.fattrib & AM_DIR) {                    /* It is a directory */
-                sprintf(&path[i], "/%s", fn);
-                res = scan_files(path);
-                path[i] = 0;
+                i = strlen(path);
+                sprintf(&path[i], "/%s", fno.fname);
+                res = scan_files(path);                    /* Enter the directory */
                 if (res != FR_OK) break;
+                path[i] = 0;
             } else {                                       /* It is a file. */
-                printf("%s/%s\n", path, fn);
+                printf("%s/%s\n", path, fno.fname);
             }
         }
         f_closedir(&dir)
@@ -111,6 +98,23 @@ FRESULT scan_files (
 
     return res;
 }
+
+
+int main (void)
+{
+    FATFS fs;
+    FRESULT res;
+    char buff[256];
+
+
+    res = f_mount(&fs, "", 1);
+    if (res == FR_OK) {
+        strcpy(buff, "/");
+        res = scan_files(buff);
+    }
+
+    return res;
+}