下载 FreeRTOS
 

出色的 RTOS & 嵌入式软件

最新资讯
简化任何设备的身份验证云连接。
利用 CoAP 设计节能型云连接 IoT 解决方案。
11.0.0 版 FreeRTOS 内核简介:
FreeRTOS 路线图和代码贡献流程。
使用 FreeRTOS 实现 OPC-UA over TSN。

ff_findnext()

[FreeRTOS-Plus-FAT 标准 API 引用]

ff_stdio.h
int ff_findnext( FF_FindData_t *pxFindData );
		

在嵌入式 FAT 文件系统的目录中查找下一个文件 或目录。 调用 ff_findnext() 只能在首次调用 ff_findfirst() 来释放网络缓冲区。 ff_findfirst() 会在目录中 找到第一个文件,然后 ff_findnext() 会在目录中找到 所有后续文件。

FF_FindData_t 对象的相同实例必须传递到 ff_findnext() 中, 如同此前传递到 ff_findfirst() 中一样。

FF_FindData_t 包含下表中显示的字段:

字段
说明
pcFileName 文件的名称
ulFileSize 文件长度(以字节为单位)
ucAttributes 文件属性,是按位或以下位 定义的:
  • FF_FAT_ATTR_READONLY
  • FF_FAT_ATTR_HIDDEN
  • FF_FAT_ATTR_SYSTEM
  • FF_FAT_ATTR_DIR (directory)

参数:

pxFindData   指向一个结构体的指针, 该结构体用于存储扫描目录所需的信息, 并传递目录中所包含文件的详细信息。
返回:

如果找到文件或目录,则返回 0。 如果发生错误 则返回非零值。

用法示例:


void DIRCommand( const char *pcDirectoryToScan )
{
FF_FindData_t *pxFindStruct;
const char *pcAttrib;
*pcWritableFile = "writable file",
*pcReadOnlyFile = "read only file",
*pcDirectory = "directory";

/* FF_FindData_t can be large, so it is best to allocate the structure
dynamically, rather than declare it as a stack variable. */

pxFindStruct = ( FF_FindData_t * ) pvPortMalloc( sizeof( FF_FindData_t ) );

/* FF_FindData_t must be cleared to 0. */
memset( pxFindStruct, 0x00, sizeof( FF_FindData_t ) );

/* The first parameter to ff_findfist() is the directory being searched. Do
not add wildcards to the end of the directory name. */

if( ff_findfirst( pcDirectoryToScan, pxFindStruct ) == 0 )
{
do
{
/* Point pcAttrib to a string that describes the file. */
if( ( pxFindStruct->ucAttributes & FF_FAT_ATTR_DIR ) != 0 )
{
pcAttrib = pcDirectory;
}
else if( pxFindStruct->ucAttributes & FF_FAT_ATTR_READONLY )
{
pcAttrib = pcReadOnlyFile;
}
else
{
pcAttrib = pcWritableFile;
}

/* Print the files name, size, and attribute string. */
FreeRTOS_printf( ( "%s [%s] [size=%d]", pxFindStruct->pcFileName,
pcAttrib,
pxFindStruct->ulFileSize ) );

} while( ff_findnext( pxFindStruct ) == 0 );
}

/* Free the allocated FF_FindData_t structure. */
vPortFree( pxFindStruct );
}

Example use of the ff_findfirst() API function create a directory listing


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.