Step 2: Index Files on SD card

Picture of Index Files on SD card
First you need to write a callback for the Filesystem to capture data on each file as it is read:

struct sPlaylist {
unsigned int CurrentFile;
unsigned int FileCount;
unsigned int FileIndex;
} Playlist;

char IndexWavFile(unsigned char Filename[],unsigned char Extension[])
if(Extension[0]==87 && Extension[1]==65 && Extension[2]==86)
return ThinFAT_Fail;
The code above recive the filename and extension of the file being opened.  it then checks the file extension if it is 'wav' you can check any file extension useing the following table as it's acsii encoded:

the callback returns a fail for all of the files as it's only meant to index files.  you can use this same callback for indexing folders too.

once you have made the callback for indexing these files you can then hand this callback to the filesystem to be run for each of the files or folders found in the current folder.  the end of file callback needs to be included even if it's not going to be used.

// Find a file
ThinFAT_FindFile((*IndexWavFile), (*EndWavFile));
// Find a folder
ThinFAT_FindFolder((*IndexFolders), (*EndWavFile));