fno.fname的Fatfs字符串比较

问题描述 投票:0回答:1

我在读取SD卡上的文件大小时遇到​​问题。这些文件的大小在应用程序中会有所不同,因此,我需要获取文件的大小。如果运行下面的代码,则可以看到目录中的文件及其大小。

我需要做的是将DATA.CSV文件的大小存储为变量。当清单为fno.fsize]时,如何添加比较以获取"data.csv

此打印输出:

00>  Listing directory: /00>         0  EVENTLOG.CSV   <DIR>   SYSTEM~1   183600  DATA.CSV ```
void Get_data_csv_file_size()//of the data csv
{
   if(Logging_UART_SD_CARD == true){NRF_LOG_INFO("\r\n Listing directory: /");}
    ff_result = f_opendir(&dir, "/");
    if (ff_result)
    {
        if(Logging_UART_SD_CARD == true){NRF_LOG_INFO("Directory listing failed!");}
    }
    do
    {
        ff_result = f_readdir(&dir, &fno);
        if (ff_result != FR_OK)
        {
            if(Logging_UART_SD_CARD == true){NRF_LOG_INFO("Directory read failed.");}
        }
        if (fno.fname[0])
        {
            if (fno.fattrib & AM_DIR)
            {
                if(Logging_UART_SD_CARD == true){NRF_LOG_RAW_INFO("   <DIR>   %s",(uint32_t)fno.fname);}
            }
            else
            {
                if(Logging_UART_SD_CARD == true){NRF_LOG_RAW_INFO("%9lu  %s", fno.fsize, (uint32_t)fno.fname);}

                if(strcmp((uint32_t)fno.fname, "data.csv")==0)//Convert both to a uint32_t
                {
                    Size_of_file = fno.fsize;//Set the size of the file
                    //Does not get to here
                }
            }
        }
    }
    while (fno.fname[0]);
}


注意,这是使用臂板在C中编程的。我需要执行什么操作才能获取文件大小?

我想要类似的东西:

   if(fno.name == "data.csv")
   {
       Size_of_file = fno.fsize;//Set the size of the file
   }

我在读取SD卡上的文件大小时遇到​​问题。这些文件的大小在应用程序中会有所不同,因此,我需要获取文件的大小。如果我运行下面的代码,我可以...

c string compare sd-card fatfs
1个回答
0
投票

找到了使用snprintf的解决方案,需要将fno.fname转换为字符串以比较结果。

© www.soinside.com 2019 - 2024. All rights reserved.