其他分享
首页 > 其他分享> > 功能打印出SD卡MUSIC内,所有文件。

功能打印出SD卡MUSIC内,所有文件。

作者:互联网

功能打印出SD卡MUSIC内,所有文件。

MUSIC 文件下,若还有文件,也能扫描出来

源码:

DIR dir1;
FILINFO fno1;
char path[256] = {0};
UINT i =0;
FRESULT scan_files (char* path)
{
	res = f_opendir(&dir1, path);
	
	if(FR_OK == res)
	{
		for(;;)
		{
			res = f_readdir(&dir1, &fno1);    //读目录
			if(FR_OK != res || 0 == fno1.fname[0]) break; ///* Break on error or end of dir */
			if(fno1.fattrib & AM_DIR) //属性为目录
			{
				i = strlen(path);
                if('.' != fno1.fname[0]) //. .. AA2 
				{
					sprintf(&path[i], "/%s", fno1.fname); 
					res = scan_files(path);
					if(FR_OK != res) break;
					path[i] = 0;
				}
			}
			else
			{
				printf("%s %s\n",path, fno1.fname); //0:/AA1/AA2/AA3 df.txt
			}
		}
		//f_closedir(&dir1);
	}
	return res;
}

int dir_test(void)
{
	strcpy(path, "0:/MUSIC");
	res = scan_files(path);

	return res;	
}

 

运行结果
0:/MUSIC HELLO.mp3
0:/MUSIC 薛之谦~1.MP3
0:/MUSIC DEFAUL~1.WMA
0:/MUSIC RINGTO~1.WMA
0:/MUSIC RINGTO~2.WMA
0:/MUSIC RINGTO~3.WMA
0:/MUSIC RINGTO~4.WMA
0:/MUSIC RIAB98~1.WMA
0:/MUSIC RIF0DC~1.WMA
0:/MUSIC RID564~1.WMA
0:/MUSIC RI9B35~1.WMA
0:/MUSIC RI70DC~1.WMA
0:/MUSIC RI35A2~1.WMA
0:/MUSIC/ABC 小张宇~1.MP3

 

标签:dir1,fno1,res,打印,MUSIC,path,WMA,SD
来源: https://blog.csdn.net/happygrilclh/article/details/111054851