Automatic folder creation & date stamping

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • Automatic folder creation & date stamping

    Hello,

    I'm working on PSoC 4BLE. I created a project using emFile(SPI) component for SD card. I'm able to store data in folder & file. I want to store the data according to time. I want to store today's data in folder name as 01/20/2016, tomorrow's data in another folder name as 01/21/2016 like that.It means folder will create by daily basis & data will store in itso whenever i need previous data i can fetch the data using sd card date folder. I tried so many things there but the structure is const char type. so i'm not able to pass a variable there.I'm attaching a file here please review it & give me some suggestions.

    Thanks in advance for your help.
    Files
    • SD Card.txt

      (8.47 kB, downloaded 1,358 times, last: )
  • Hello chopra.arpita92,

    It seems that you are trying to create a file with a name longer than 8 characters.
    This works only when the support for long file names is enabled in the file system.
    The support for long file names is disabled by default. It can be enabled by calling
    FS_FAT_SupportLFN() API function.

    Would it be possible to try this in your application?forum.segger.com/index.php?page=User&userID=5597

    Best regards,
    Marius
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Hello,

    Would it be possible to provide more details about how do you get this date?

    Best regards,
    Marius
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Hello Marius,

    I'm using RTC here but in programming i'm getting correct date & time in length = sprintf() but here whem i'm trying to get the time & date it is not giving me correct date. Here is an API U32 FS_X_GetTimeDate(void)
    {
    U32 r;
    U16 Sec, Min, Hour;
    U16 Day, Month, Year;

    Sec = 0; /* 0 based. Valid range: 0..59 */
    Min = 0; /* 0 based. Valid range: 0..59 */
    Hour = 0; /* 0 based. Valid range: 0..23 */
    Day = 1; /* 1 based. Means that 1 is 1. Valid range is 1..31 (depending on month) */
    Month = 1; /* 1 based. Means that January is 1. Valid range is 1..12. */
    Year = 0; /* 1980 based. Means that 2007 would be 27. */
    r = Sec / 2 + (Min << 5) + (Hour << 11);
    r |= (U32)(Day + (Month << 1) + (Year << 16)) << 20;
    return r;
    }

    Is this effecting to my code. Please let me know.

    Thanks,
  • Hello,

    The file system uses the FS_X_GetTimeDate() function to generate the timestamps of files and directories.
    In order to have correct timestamps, you should add calls to your RTC routines in this function
    as documented in the emFile manual.

    Best regards,
    Marius
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Thank you Marius,

    Now i'm getting all the correct values. I just want to ask one thing which is that i want to put long directory name (01-27-2016) according to time stamping but i'm not able to do this. if i will remove dash(-) between them then i'll get correct (01272016) nos but with dash it is not possible. is there something for long directory name.

    Thanks,
  • Hello,

    I tested here with the version 4.00b of the file system.
    With support for long file names enabled, I was able to successfully create a file with the name "01-27-2016".
    Which version of the file system are you using?
    Does the file system report any errors when you try to create the file?

    Best regards,
    Marius
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Hello Marius,

    Thank you for your time. I'm also able to give the file name according to date stamping. I want to put long folder (directory) name. I'm getting a folder from FS_Mkdir(""), I want to put directory name as 01-27-2016, but now i'm just getting(01272016). FS_FAT_SupportLFN(); for long file name. Is there something for long directory(folder) name.

    Thanks,

    The post was edited 1 time, last by chopra.arpita92 ().

  • Hello,

    The file system treats the name of the files and of the directories in the same way.
    FS_FAT_SupportLFN() enables the support for long file name for files as well as for directories.
    Could you please check the return value of FS_MkDir()? The error code should give
    a hint about what went wrong during the operation.

    Best regards,
    Marius
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • Hello Marius,

    I'm already using FS_FAT_SupportLFN(); but not able to capture date. Please check the bold area. If i'm putting dash it is not creating folder. I need to add any source or header file? Please let me know.

    FS_Init();
    void FS_FAT_SupportLFN();
    /* Get volume name of SD card #0 */
    if(0 != FS_GetVolumeName(0u, &sdVolName[0], 9u))
    {
    /* Getting volume name succeeded */
    UART_UartPutString(" mixBuffer ");
    UART_UartPutString(sdVolName);
    }
    else
    {
    /* Operation Failed - indicate this */
    UART_UartPutString("Failed to get mixBuffer");
    }

    /* Extend support for file creation with long name. */


    /* Initialization of Folder and File creation at the beginning of execution. */

    /* Get Date and Time from RTC */
    time1 = RTC_GetTime();
    date=RTC_GetDate();

    /* Capture File Name for MM-DD-YYYY */
    sprintf(dir_name, "%02lu%02lu%02lu", RTC_GetMonth(date),RTC_GetDay(date),RTC_GetYear(date));

    /* Capture File Name for Dir_name\HH.txt */
    sprintf(sdFile, "%s\\%02lu-%02lu.txt", dir_name, RTC_GetDay(date), RTC_GetHours(time1));

    /* Create Directory */
    FS_MkDir(dir_name);

    Thanks,
  • Hello,

    Could you please check the return value of FS_MkDir()?

    In case of an error the function returns a negative value
    indicating the reason why the operation failed.
    The possible error codes are defined at the beginning of the FS.h file (FS_ERRCODE_...)
    You can get a short text description of the error
    by calling FS_ErrorNo2Text() with the error code as parameter.

    Best regards,
    Marius
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.