How To Get TimeStamp of a File -- File.GetCreationTime Not Working
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: How To Get TimeStamp of a File -- File.GetCreationTime Not Working

  1. #1
    Join Date
    Jul 2013
    Posts
    7

    How To Get TimeStamp of a File -- File.GetCreationTime Not Working

    Hi

    I've searched around the net and the conventional answer for getting the timestamp of a file is to use
    File.GetCreationTime. But for some reason, the return DateTime is always different than the timestamp of the file shown in Windows Exlorer.

    I'd post sample code, but really, it's a one-liner with a call to File.GetCreationTime();

  2. #2
    Arjay's Avatar
    Arjay is online now Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,247

    Re: How To Get TimeStamp of a File -- File.GetCreationTime Not Working

    Are you confusing the "Date Modified" with the "Date Created"?

    Code:
                var fileName = "c:\\formatter.log";
    
                var dt1 = File.GetCreationTime(fileName);   // Date Created
                var dt2 = File.GetLastWriteTime(fileName); // Date Modified

  3. #3
    Join Date
    Jul 2013
    Posts
    7

    Re: How To Get TimeStamp of a File -- File.GetCreationTime Not Working

    Thanks, yes, that's what happened.

    It would seem that the "LastWriteTime" would be a date that is later in time (more recent) than "CreationTime", but for some reason, it's backwards for me. I think it's because the files that I'm operating on are files that have been moved from another folder, and therefore, the creation time would be the time of when it was moved compared to the timestamp, which is carried over as the same timestamp of the file before before it was moved.

  4. #4
    Arjay's Avatar
    Arjay is online now Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,247

    Re: How To Get TimeStamp of a File -- File.GetCreationTime Not Working

    Yes, I believe you are correct. If you want, you can use the File.WriteXXX methods to adjust the creation times.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center