stm32 mmc卡扫描指定文件夹下的所有文件 串口输出(文件名长度有限制)
2024-10-17 来源:cnblogs
硬件环境:神州一号开发板
软件环境:mdk
1、sd卡初始化
2、f_mount
3、扫描函数如下:
#define _USE_LFN 0
FRESULT scan_files (char* path)
{
FRESULT res;
FILINFO fno;
DIR dir;
int i;
char *fn;
#if _USE_LFN
static char lfn[_MAX_LFN * (_DF1S ? 2 : 1) + 1];
fno.lfname = lfn;
fno.lfsize = sizeof(lfn);
#endif
res = f_opendir(&dir, path);
if (res == FR_OK)
{
i = strlen(path);
for (;;) {
res = f_readdir(&dir, &fno);
if (res != FR_OK || fno.fname[0] == 0) break;
if (fno.fname[0] == '.') continue;
#if _USE_LFN
fn = *fno.lfname ? fno.lfname : fno.fname;
#else
fn = fno.fname;
#endif
if (fno.fattrib & AM_DIR)
{
sprintf(&path[i], '/%s', fn);
res = scan_files(path);
if (res != FR_OK) break;
path[i] = 0;
}
else {
//printf('%s/%sn', path, fn);
//USART1_Puts(path);
USART1_Puts(fn);//输出指定文件夹下的文件名称
USART1_Puts('rn');
}
}
}
else
{
USART1_Puts('open dir failedn');
}
return res;
}
4、如果扫描卡的music目录下的文件,则
scan_files('music');即可
上一篇:stm32若干技巧