LPC5411x mp3制作 之遍历 SD卡内 所用MP3文件

记录一下自己编程中遇到的问题及解决的方法:

目的:遍历sd中所有的文件夹,把mp3格式的歌曲的路径提取出来。

方法:已经移植好的fatfs 嵌入式文件 系统

/*!
 * @brief Traversing files of the specified file type in the directory
 *
 * @param root directory
 * @param the type need to be find (file suffix)
 * @param the type need to be find (file suffix)
 * @param This structure is used to store the results
 * @return Return the result of the open directory
 */
char scan_files(char *filePath,char *fileSuffix1,char *fileSuffix2,Mp3File *resultFile)
{
    FRESULT res;
    DIR dir;
    static int i=0;  
    FILINFO fileinfo;
    char path[MAX_FILE_PATH_LENGTH];
    char tempPath[MAX_FILE_PATH_LENGTH];
    
    strcpy(path,filePath);
    res = f_opendir(&dir,(const TCHAR*)path);                    //open path
    if (res == FR_OK) 
     {  
        strcat(path,"/");
        while(1)
        {
            res = f_readdir(&dir, &fileinfo);                   //Read each file in the path in turn
            if (res != FR_OK || fileinfo.fname[0] == 0) break;  
            if (fileinfo.fname[0] == '.') continue;             
            if (fileinfo.fattrib & AM_DIR) {                     //Determine if it is a folder
                strcpy(tempPath,path);
                strcat(tempPath,fileinfo.fname);
                //strcat(path,fileinfo.fname);
                
                PRINTF("filedirpath=%s\n",tempPath);
                res = scan_files(tempPath,fileSuffix1,fileSuffix2,resultFile);
               if (res != FR_OK) break;
           } else {
               if(strstr(fileinfo.fname,fileSuffix1) || strstr(fileinfo.fname,fileSuffix2)) //Determine if it is the file you are looking for
               {
//                   PRINTF("current path =%s\n",path);
//                   PRINTF ("mp3 file name = %s\n",fileinfo.fname);
                   strcpy(tempPath,path);
                   strcat(tempPath,fileinfo.fname);
                   strcpy(resultFile->name[i] ,tempPath);
                   resultFile->length=i;
                   i++;
               }
           }        
        } 
        f_closedir(&dir);
    }     
 return res;      
}

调用方法如下:

typedef struct mp3file{
    char name[MAX_MP3_FILE_NUM][MAX_FILE_PATH_LENGTH];
    int length;
}Mp3File;


Mp3File mp3File;

scan_files("4:",".mp3",".MP3",&mp3File);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值