LPC 5411 x mp 3作成のSDカード内を巡るMP 3ファイル
2462 ワード
自分のプログラミングで出会った問題と解決方法を記録します.
目的:sdのすべてのフォルダを巡り、mp 3形式の曲のパスを抽出する.
方法:すでに移植したfatfs埋め込みファイルシステム
呼び出し方法は次のとおりです.
目的:sdのすべてのフォルダを巡り、mp 3形式の曲のパスを抽出する.
方法:すでに移植した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
",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
",path);
// PRINTF ("mp3 file name = %s
",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);