Page 1 of 1

如何枚举根目录下的文件

Posted: Sat Apr 18, 2020 6:23 am
by fifacoco
我在应用中使用了spiffs,需要枚举根目录/spiflash下的所有文件,使用了如下代码:
DIR *ptDir = opendir(“/spiflash”);
struct dirent *ptDirent = NULL;
SpiFlash_FatFsInit();

//列出所有根目录下的文件
while(1)
{
ptDirent = readdir(ptDir);
if(ptDirent == NULL)
{
AUDIOGET_INFO("read dir over");
return;
}
else
{
AUDIOGET_INFO("file name is %s", ptDirent->d_name);
}
}
程序就异常重启了,麻烦提供一下枚举根目录下文件的方法,谢谢