Main Site Documentation

SD File Create DateTime?


#1

I am working on a program which logs data to a SD. The filename contains the date and time.

When looking at the files on the SD I noticed that while the filename was correct, the creation date of the that showed up on a PC was wrong.

I also noticed that when creating a file on the SD, captialization is required for the filesystem name. \sd\ does not work. \SD\ does?

Following is a code sample which demonstrates how I am setting the real-time and .NETMF clock, writting to the SD, and looking at the resultant times for the new file.

using System;
using System.IO;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.IO;
using GHIElectronics.NETMF.IO;
using GHIElectronics.NETMF.Hardware;

namespace SDTests
{
    public class Program
    {
        public static void Main()
        {
            // see if real-time clock has been set
            if (!RealTimeClock.IsTimeValid)
            {
                Debug.Print("Setting real-time clock");
                RealTimeClock.SetTime(new DateTime(2010, 07, 03, 21, 30, 00));  
            }
            else
            {
                Debug.Print("Real-time clock is valid");
            }
            // set the NETMF clock from the real-time clock
            Utility.SetLocalTime(RealTimeClock.GetTime());

            Debug.Print("Current time is " + DateTime.Now.ToString());

            // wait for sd to be recognized
            while (!PersistentStorage.DetectSDCard())
            {
                Thread.Sleep(100);
            }

            // mount sd
            PersistentStorage sdPS = new PersistentStorage("SD");
            sdPS.MountFileSystem();

            //StreamWriter wr = new StreamWriter("\\sd\\Test.txt", false); // causes exception
            StreamWriter wr = new StreamWriter("\\SD\\Test.txt", false);
            
            // write to file
            for (int i = 1; i <= 10; i++)
                wr.WriteLine("Line " + i.ToString());

            // close file
            wr.Flush();
            wr.Close();
            VolumeInfo.GetVolumes()[0].FlushAll();

            // see what is on SD
            String[] files = Directory.GetFiles("\\SD\\");
            for (int i = 0; i < files.Length; i++)
            {
                FileInfo info = new FileInfo(files[i]);
                Debug.Print(files[i] + " CreationTime: " + info.CreationTime.ToString());
                Debug.Print(files[i] + " LastAccessTime: " + info.LastAccessTime.ToString());
                Debug.Print(files[i] + " LastWriteTime: " + info.LastWriteTime.ToString());
                File.Delete(info.FullName);
            }

            Thread.Sleep(Timeout.Infinite);
        }
    }
}

The program output:

Real-time clock is valid
Current time is 07/03/2010 22:19:33
\SD\Test.txt CreationTime: 01/01/1985 00:28:49
\SD\Test.txt LastAccessTime: 01/01/1985 00:00:00
\SD\Test.txt LastWriteTime: 01/01/1985 00:28:48

What have I done wrong?

Thanks,
Mike


#2

Yes, you need to have the “SD” in all caps. This is normal.

I did squawk a while back about the creation date given to files a while back, but it never really got answered.

As far as I can tell, you are doing everything right, or at least this is how I set a similar application up.


#3

Hi Chris:

In the Microsoft world filenames are case insensitive. So, the capitial SD is not normal, just different. :expressionless:

I had did a search before posting, but did not see your prior post on the creation date issue.

Maybe we will get an answer this time :stuck_out_tongue:


#4

Hi Mike,

The SD card creation date thing was in a private email, so that’s why it didn’t show up.


#5

No response from ghi on this issue.


#6

The question was asked on weekend and today is a holiday in USA so most engineers are not here. You will get an answer tomorrow from our file system expert, Mike!


#7

Sorry, I did not realize that you guys were allowed to take time off. :stuck_out_tongue:


#8

The date/time is not correct. We are working with Microsoft on a fix.


#9

Great, thanks Mike!


#10

Thanks Mike!