第25章 串行FLASH文件系统FatFs (12)

16     printf("》设备总空间:%10lu KB\n》可用空间:  %10lu KB\n",

17                                              tot_sect *4, fre_sect *4);

18

19     printf("\n******** 文件定位和格式化写入功能测试 ********\r\n");

20     res_flash = f_open(&fnew, "1:FatFs读写测试文件.txt",

21                                     FA_OPEN_EXISTING|FA_WRITE|FA_READ );

22     if ( res_flash == FR_OK ) {

23         /*  文件定位 */

24         res_flash = f_lseek(&fnew,f_size(&fnew)-1);

25         if (res_flash == FR_OK) {

26          /* 格式化写入,参数格式类似printf函数 */

27          f_printf(&fnew,"\n在原来文件新添加一行内容\n");

28          f_printf(&fnew,"》设备总空间:%10lu KB\n》可用空间:  %10lu KB\n",

29                                                tot_sect *4, fre_sect *4);

30             /*  文件定位到文件起始位置 */

31             res_flash = f_lseek(&fnew,0);

32             /* 读取文件所有内容到缓存区 */

33             res_flash = f_read(&fnew,readbuffer,f_size(&fnew),&fnum);

34             if (res_flash == FR_OK) {

35                 printf("》文件内容:\n%s\n",readbuffer);

36             }

37         }

38         f_close(&fnew);

39

40         printf("\n********** 目录创建和重命名功能测试 **********\r\n");

41         /* 尝试打开目录 */

42         res_flash=f_opendir(&dir,"0:TestDir");

43         if (res_flash!=FR_OK) {

44             /* 打开目录失败,就创建目录 */

45             res_flash=f_mkdir("0:TestDir");

46         } else {

47             /* 如果目录已经存在,关闭它 */

48             res_flash=f_closedir(&dir);

49             /* 删除文件 */

50             f_unlink("0:TestDir/testdir.txt");

51         }

52         if (res_flash==FR_OK) {

53             /* 重命名并移动文件 */

54             res_flash=f_rename("0:FatFs读写测试文件.txt",

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zwzsjd.html