FATFS | 中文显示 | 长文件名
引:
FatFs 从 0.07 版本开始支持长文件名(LFN)。现在最新版本为0.14版本(下载链接:http://elm-chan.org/fsw/ff/00index_e.html),支持最长的字符长度为255,可看宏定义#define FF_MAX_LFN 255;
一、支持中文格式步骤
1.将 FF_USE_LFN宏定义定义为1
FF_USE_LFN代表意思:
0: Disable LFN,关闭长文件功能。
1:使用一个静态内存区来保存长文件名。
2:动态分配STACK保存文件名。
3:在HEAP上启用LFN动态工作缓冲区,动态分配HEAP保存文件名。
2.将FF_CODE_PAGE定义为936,使用简体中文格式
#define FF_CODE_PAGE 936
/* This option specifies the OEM code page to be used on the target system.
/ Incorrect code page setting can cause a file open failure.
/
/ 437 - U.S.
/ 720 - Arabic
/ 737 - Greek
/ 771 - KBL
/ 775 - Baltic
/ 850 - Latin 1
/ 852 - Latin 2
/ 855 - Cyrillic
/ 857 - Turkish
/ 860 - Portuguese
/ 861 - Icelandic
/ 862 - Hebrew
/ 863 - Canadian French
/ 864 - Arabic
/ 865 - Nordic
/ 866 - Russian
/ 869 - Greek 2
/ 932 - Japanese (DBCS)
/ 936 - Simplified Chinese (DBCS)
/ 949 - Korean (DBCS)
/ 950 - Traditional Chinese (DBCS)
/ 0 - Include all code pages above and configured by f_setcp()
*/
二、验证方法:
1.代码
DIR dirs;
FILINFO finfo;
if (f_opendir(&dirs, "project") == FR_OK) //打开文件夹
{
while (f_readdir(&dirs, &finfo) == FR_OK) //按照顺序读文件夹
{
if(!finfo.fname[0]) break; //如果文件名为 0,结束
{
if(finfo.fattrib == AM_ARC) //判断文件属性
printf("filename : %s\r\n",finfo.fname);
}
}
}