disk_initialize(0);
printf("\n\r f_mount %d\r\n", f_mount(0, &fs[0]));
printf("\n\r----------------------------------------------------\n\r");
if (f_opendir(&dirs, path) == FR_OK)
{
while (f_readdir(&dirs, &finfo) == FR_OK)
{
if (finfo.fattrib & AM_ARC)
{
if(!finfo.fname[0])
break;
printf("\n\r file name is: %s\n",finfo.fname);
printf("\n\r file size is: %d ", finfo.fsize);
printf("\n\r 文件内容:\n\r");
if(File_type_Check( (u8 *)finfo.fname, "txt"))
{
res = f_open(&fsrc, finfo.fname, FA_OPEN_EXISTING | FA_READ);
i=0;
f_lseek(&fsrc,0);
do
{
f_lseek(&fsrc,512*i);
f_read(&fsrc,buf1,512,&br);
i++;
printf("%s", buf1);
}
while(i< (finfo.fsize/512));
f_lseek(&fsrc,512*i);
BufferSet(buf1, 0, 512);
f_read(&fsrc,buf1,(finfo.fsize%512),&br);
printf("%s", buf1);
f_close(&fsrc);
}
}
else
{
printf("\n\r Path name is: %s", finfo.fname);
continue;
}
}
}
else
{
printf("\n\r err: f_opendir\n\r");
}
printf("\n\r----------------------------------------------------\n\r");
}
读取txt文件好像没问题,但是读取MP3,500多K 变成了100多K |