您的位置:首页 > 其它

STM32+SD卡 利用FATFS文件系统创建文件夹并新建txt文件

2017-11-03 10:05 1346 查看
这几天在移植FATFS文件系统,在移植过程中需要新建文件夹下创建新的cfg文件,查找资料后发现需要用到以下函数:

f_mkdir("0:/2017110223");//新建文件夹,其中2017110223是文件夹名称

f_open(filescr1, "0:2017110223/201711011.txt", FA_OPEN_NEW_COVER);//在新建的文件夹下创建新的txt文本文件

新建完成之后要记得关闭该文件,否则就会出错。

f_res = f_close(filescr1);

在移植FATFS文件系统的时候我们可以用随时查看文件操作函数的返回值,针对这些返回值都有特定的意义,针对这些返回值我们可以很快锁定问题。

typedef enum {
FR_OK = 0,
/* (0) Succeeded */
FR_DISK_ERR,
/* (1) A hard error occurred in the low level disk I/O layer */
FR_INT_ERR,
/* (2) Assertion failed */
FR_NOT_READY,
/* (3) The physical drive cannot work */
FR_NO_FILE,
/* (4) Could not find the file */
FR_NO_PATH,
/* (5) Could not find the path */
FR_INVALID_NAME,
/* (6) The path name format is invalid */
FR_DENIED,
/* (7) Access denied due to prohibited access or directory full */
FR_EXIST,
/* (8) Access denied due to prohibited access */
FR_INVALID_OBJECT,
/* (9) The file/directory object is invalid */
FR_WR
925b
ITE_PROTECTED,
/* (10) The physical drive is write protected */
FR_INVALID_DRIVE,
/* (11) The logical drive number is invalid */
FR_NOT_ENABLED,
/* (12) The volume has no work area */
FR_NO_FILESYSTEM,
/* (13) There is no valid FAT volume */
FR_MKFS_ABORTED,
/* (14) The f_mkfs() aborted due to any parameter error */
FR_TIMEOUT,
/* (15) Could not get a grant to access the volume within defined period */
FR_LOCKED,
/* (16) The operation is rejected according to the file sharing policy */
FR_NOT_ENOUGH_CORE,
/* (17) LFN working buffer could not be allocated */
FR_TOO_MANY_OPEN_FILES,
/* (18) Number of open files > _FS_SHARE */
FR_INVALID_PARAMETER
/* (19) Given parameter is invalid */

} FRESULT;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: