单片机/MCU论坛
直播中

恩可口

8年用户 686经验值
私信 关注
[问答]

FATFS文件系统有读取文件日期信息的函数吗?

FATFS文件系统,有读取文件日期信息的函数吗?

回帖(1)

罗茵

2023-10-16 10:53:27
没有直接的函数,需要用到`f_stat`获取文件状态后,从间接返回的数据结构类型FILINFO 信息中提取。函数的介绍如下:
```

FRESULT f_stat (
const XCHAR* FileName   /@@* 文件名或目录名的指针 */
FILINFO* FileInfo        /@@* FILINFO结构的指针 */
);
```
其中FILINFO的定义见下:
```
/@@* File information structure (FILINFO) */
typedef struct {
    FSIZE_t    fsize;            /@@* File size */
    WORD    fdate;            /@@* Modified date */
    WORD    ftime;            /@@* Modified time */
    BYTE    fattrib;        /@@* File attribute */
#if FF_USE_LFN
    TCHAR    altname[FF_SFN_BUF + 1];/@@* Altenative file name */
    TCHAR    fname[FF_LFN_BUF + 1];    /@@* Primary file name */
#else
    TCHAR    fname[12 + 1];    /@@* File name */
#endif
} FILINFO;

```
其中 fdate和ftime部分就是文件最后编辑时间信息(对目录是创建)。
分别的格式定义为
fdate:Indicates the date that the file was modified or the directory was created.
            bit15:9
                Year origin from 1980 (0..127)
            bit8:5
                Month (1..12)
            bit4:0
                Day (1..31)
ftime:Indicates the time that the file was modified or the directory was created.
            bit15:11
                Hour (0..23)
            bit10:5
                Minute (0..59)
            bit4:0
                Second / 2 (0..29)
举报

更多回帖

发帖
×
20
完善资料,
赚取积分