2015-07-08 15:39:24 +00:00
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
< html lang = "en" >
< head >
< meta http-equiv = "Content-Type" content = "text/html; charset=iso-8859-1" >
< meta http-equiv = "Content-Style-Type" content = "text/css" >
< link rel = "up" title = "FatFs" href = "../00index_e.html" >
< link rel = "alternate" hreflang = "ja" title = "Japanese" href = "../ja/readdir.html" >
< link rel = "stylesheet" href = "../css_e.css" type = "text/css" media = "screen" title = "ELM Default" >
< title > FatFs - f_readdir< / title >
< / head >
< body >
< div class = "para func" >
< h2 > f_readdir< / h2 >
< p > The f_readdir function reads directory entries.< / p >
< pre >
FRESULT f_readdir (
DIR* < span class = "arg" > dp< / span > , < span class = "c" > /* [IN] Directory object */< / span >
FILINFO* < span class = "arg" > fno< / span > < span class = "c" > /* [OUT] File information structure */< / span >
);
< / pre >
< / div >
< div class = "para arg" >
< h4 > Parameters< / h4 >
< dl class = "par" >
< dt > dp< / dt >
2016-04-19 16:51:31 +00:00
< dd > Pointer to the directory object created by < tt > f_opendir< / tt > function.< / dd >
2015-07-08 15:39:24 +00:00
< dt > fno< / dt >
2016-04-19 16:51:31 +00:00
< dd > Pointer to the file information structure to store the information about read item.< / dd >
2015-07-08 15:39:24 +00:00
< / dl >
< / div >
< div class = "para ret" >
< h4 > Return Values< / h4 >
< p >
< a href = "rc.html#ok" > FR_OK< / a > ,
< a href = "rc.html#de" > FR_DISK_ERR< / a > ,
< a href = "rc.html#ie" > FR_INT_ERR< / a > ,
< a href = "rc.html#io" > FR_INVALID_OBJECT< / a > ,
< a href = "rc.html#tm" > FR_TIMEOUT< / a > ,
< a href = "rc.html#nc" > FR_NOT_ENOUGH_CORE< / a >
< / p >
< / div >
< div class = "para desc" >
< h4 > Description< / h4 >
2016-04-19 16:51:31 +00:00
< p > The < tt > f_readdir< / tt > function reads directory items, informations about file and directory, in sequence. All items in the directory can be read by calling < tt > f_readdir< / tt > function repeatedly. When relative path feature is enabled (< tt > < a href = "config.html#fs_rpath" > _FS_RPATH< / a > > = 1< / tt > ), dot entries (< tt > "."< / tt > and < tt > ".."< / tt > ) 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 stored into the < tt > fno-> fname[]< / tt > without any error. When a null pointer is given to the < tt class = "arg" > fno< / tt > , the read index of the directory object is rewinded.< / p >
< p > When LFN feature is enabled, < tt > fno-> lfname< / tt > and < tt > fno-> lfsize< / tt > in the file information structure must be initialized with valid value prior to use it. The < tt > lfname< / tt > points the LFN read buffer. The < tt > lfsize< / tt > is size of the LFN read buffer in unit of < tt > TCHAR< / tt > . If the LFN is not needed, set a null pointer to the < tt > lfname< / tt > and the LFN is not returned. A null string will be returned into the LFN read buffer in case of following conditions.< / p >
2015-07-08 15:39:24 +00:00
< ul >
2016-04-19 16:51:31 +00:00
< li > The directory item has no LFN information. In this case, lower case characters can be contained in the < tt > fname[]< / tt > .< / li >
2015-07-08 15:39:24 +00:00
< li > Either the size of read buffer or LFN working buffer is insufficient for the LFN.< / li >
2016-04-19 16:51:31 +00:00
< li > The LFN contains any Unicode character that cannot be converted to OEM code. (Not the case at Unicode API configuration)< / li >
2015-07-08 15:39:24 +00:00
< / ul >
< / div >
< div class = "para comp" >
< h4 > QuickInfo< / h4 >
< p > Available when < tt > _FS_MINIMIZE < = 1< / tt > .< / p >
< / div >
< div class = "para use" >
< h4 > Sample Code< / h4 >
< pre >
FRESULT scan_files (
char* path < span class = "c" > /* Start node to be scanned (also used as work area) */< / span >
)
{
FRESULT res;
FILINFO fno;
DIR dir;
int i;
char *fn; < span class = "c" > /* This function assumes non-Unicode configuration */< / span >
< span class = "k" > #if< / span > _USE_LFN
static char lfn[_MAX_LFN + 1]; < span class = "c" > /* Buffer to store the LFN */< / span >
fno.lfname = lfn;
fno.lfsize = sizeof lfn;
< span class = "k" > #endif< / span >
res = f_opendir(& dir, path); < span class = "c" > /* Open the directory */< / span >
if (res == FR_OK) {
i = strlen(path);
for (;;) {
res = f_readdir(& dir, & fno); < span class = "c" > /* Read a directory item */< / span >
if (res != FR_OK || fno.fname[0] == 0) break; < span class = "c" > /* Break on error or end of dir */< / span >
if (fno.fname[0] == '.') continue; < span class = "c" > /* Ignore dot entry */< / span >
< span class = "k" > #if< / span > _USE_LFN
fn = *fno.lfname ? fno.lfname : fno.fname;
< span class = "k" > #else< / span >
fn = fno.fname;
< span class = "k" > #endif< / span >
if (fno.fattrib & AM_DIR) { < span class = "c" > /* It is a directory */< / span >
sprintf(& path[i], "/%s", fn);
res = scan_files(path);
path[i] = 0;
if (res != FR_OK) break;
} else { < span class = "c" > /* It is a file. */< / span >
printf("%s/%s\n", path, fn);
}
}
f_closedir(& dir)
}
return res;
}
< / pre >
< / div >
< div class = "para ref" >
< h4 > See Also< / h4 >
< p > < tt > < a href = "opendir.html" > f_opendir< / a > , < a href = "closedir.html" > f_closedir< / a > , < a href = "stat.html" > f_stat< / a > , < a href = "sfileinfo.html" > FILINFO< / a > , < a href = "sdir.html" > DIR< / a > < / tt > < / p >
< / div >
< p class = "foot" > < a href = "../00index_e.html" > Return< / a > < / p >
< / body >
< / html >