none
File GetCreationTime Error? RRS feed

  • Question

  • I've been on holiday across several time zones and forgot to reset the time on my digital camera. (The camera produces a raw and a jpg at exactly the same time). I'm trying to write a quick solution to the date / time mess on my photos. I thought I'd test my plan in a Rich Text Box so I can see what it's doing before I commit. It's working ok but it keeps getting the Creation Time wrong every so often! The date it's putting in incorrectly seems to be today's, but I've no idea where it's getting the time from. I've tried changing it to GetLastWriteTime and the results are the same (precisely). Refreshes and reboots haven't helped. Windows Explorer has the correct times. 

    Code:

    For Each F_File As String In My.Computer.FileSystem.GetFiles(PathDir)
                TimeCreation = File.GetCreationTime(F_File)
                RTB1.AppendText(F_File)
                RTB1.AppendText("    ")
                RTB1.AppendText(TimeCreation)
                RTB1.AppendText("    ")
                TimeCreation = DateAdd(DateInterval.Hour, -8, TimeCreation)
                RTB1.AppendText(TimeCreation)
                RTB1.AppendText(Chr(13))
            Next

    A sample of the output is:

    E:\Chris\Photos\2018-10-10 SR\111A2147.CR2    10/10/2018 00:16:32    09/10/2018 16:16:32
    E:\Chris\Photos\2018-10-10 SR\111A2147.JPG    10/10/2018 00:16:32    09/10/2018 16:16:32
    E:\Chris\Photos\2018-10-10 SR\111A2148.CR2    10/10/2018 00:17:10    09/10/2018 16:17:10
    E:\Chris\Photos\2018-10-10 SR\111A2148.JPG    10/10/2018 00:17:10    09/10/2018 16:17:10
    E:\Chris\Photos\2018-10-10 SR\111A2149.CR2    10/10/2018 00:23:00    09/10/2018 16:23:00
    E:\Chris\Photos\2018-10-10 SR\111A2149.JPG    10/10/2018 00:23:00    09/10/2018 16:23:00
    E:\Chris\Photos\2018-10-10 SR\111A2150.CR2    10/10/2018 00:23:14    09/10/2018 16:23:14
    E:\Chris\Photos\2018-10-10 SR\111A2150.JPG    17/10/2018 09:44:02    17/10/2018 01:44:02
    E:\Chris\Photos\2018-10-10 SR\111A2151.CR2    10/10/2018 00:49:10    09/10/2018 16:49:10
    E:\Chris\Photos\2018-10-10 SR\111A2151.JPG    10/10/2018 00:49:10    09/10/2018 16:49:10
    E:\Chris\Photos\2018-10-10 SR\111A2152.CR2    10/10/2018 02:40:38    09/10/2018 18:40:38
    E:\Chris\Photos\2018-10-10 SR\111A2152.JPG    17/10/2018 09:44:05    17/10/2018 01:44:05
    E:\Chris\Photos\2018-10-10 SR\111A2153.CR2    10/10/2018 17:52:34    10/10/2018 09:52:34
    E:\Chris\Photos\2018-10-10 SR\111A2153.JPG    10/10/2018 17:52:34    10/10/2018 09:52:34
    E:\Chris\Photos\2018-10-10 SR\111A2154.CR2    10/10/2018 17:54:18    10/10/2018 09:54:18
    E:\Chris\Photos\2018-10-10 SR\111A2154.JPG    17/10/2018 09:44:12    17/10/2018 01:44:12
    E:\Chris\Photos\2018-10-10 SR\111A2155.CR2    10/10/2018 17:56:42    10/10/2018 09:56:42
    E:\Chris\Photos\2018-10-10 SR\111A2155.JPG    10/10/2018 17:56:42    10/10/2018 09:56:42
    E:\Chris\Photos\2018-10-10 SR\111A2156.CR2    10/10/2018 17:56:48    10/10/2018 09:56:48
    E:\Chris\Photos\2018-10-10 SR\111A2156.JPG    10/10/2018 17:56:48    10/10/2018 09:56:48
    E:\Chris\Photos\2018-10-10 SR\111A2157.CR2    10/10/2018 17:57:12    10/10/2018 09:57:12
    E:\Chris\Photos\2018-10-10 SR\111A2157.JPG    17/10/2018 09:44:16    17/10/2018 01:44:16

    I'm grateful for any thoughts. Thanks.


    Wednesday, October 17, 2018 8:50 PM

Answers

  • Ug. I dont really know.

    Some things have options do it this way or that way.

    There is the metafile data that is in the image file format data. Then the windows file data which is something else.

    Here I made a copy of an old file. The  LastAccessTime is different between the original (bottom) and the copy I just made with windows file explorer (top). The copy has todays date and one has the old date.

    But, still not sure what the problem is?

    Public Class Form4
        Private Sub Form4_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim fi As New IO.FileInfo("c:\bitmaps\rusty - copy.jpg")
    
            Dim s As String
            s = fi.CreationTime & vbLf &
                    fi.LastAccessTime & vbLf &
                    fi.LastWriteTime
    
            fi = New IO.FileInfo("c:\bitmaps\rusty.jpg")
            s += vbLf & "--------------" & vbLf & vbLf
    
            s += fi.CreationTime & vbLf &
                    fi.LastAccessTime & vbLf &
                    fi.LastWriteTime
    
            MsgBox(s)
    
        End Sub
    End Class

    • Marked as answer by Queheleth Monday, October 22, 2018 10:04 PM
    Friday, October 19, 2018 11:19 PM
  • Hi Tommy,

    I did look at Viorel's comment. I thought it was very helpful and could be a great work-around for my problem. I've had a preliminary look at it but I haven't managed to access the correct exif data. I need a bit more time to get my head around how to do it! 

    "Time of copy" is a very interesting suggestion. You caused my to look at the exif data in Photoshop Elements and the incorrect files have different time stamps. Photoshop shows the data in several different sections. In the "metadata" section they have the incorrect time, which does appear to be the time they were transferred - as you hinted. They also have the correct time (when taken) in the "general" data section. Whereas unaffected files have the same date in both (when taken).

    How on earth has that happened??? (I transferred the files using the Windows functionality rather than specific Canon software as I've found Windows better for separating the photos from a series of different Canon cameras.)

    Also why is Windows Explorer showing the "general" info but VB is clearly reading the "metadata"?

    • Marked as answer by Queheleth Monday, October 22, 2018 10:05 PM
    Friday, October 19, 2018 10:13 PM

All replies

  • Hi

    You say 'Windows Explorer has the correct times.', so are you saying that the windows properties of a file shows a different creation time than the time displayed by your code?

    I find it hard to believe. I have a couple of applications that do extensive file operations using such (similar ) File.GetCreationTime code , over a long time and a very large number of files and have never had such an issue.

    Perhaps the files were not saved correctly at the time of creation?


    Regards Les, Livingston, Scotland

    Wednesday, October 17, 2018 10:13 PM
  • Yes I cant duplicate the problem?

    Does your file exist And what is the time?

          E:\Chris\Photos\2018-10-10 SR\111A2152.JPG    17/10/2018 09:44:05   

    Here is an example using your code in a msgbox.


    Wednesday, October 17, 2018 10:32 PM
  • Probably you do not need the file’s date, but the picture’s date.  Maybe try BitmapMetadata.DateTaken:


    Thursday, October 18, 2018 5:38 AM
  • Hi,

    These are photos taken in different time zones. Do you want to change the time taken for these photos to the current time zone?

    https://docs.microsoft.com/en-us/dotnet/standard/datetime/converting-between-time-zones

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, October 18, 2018 6:16 AM
  • Thank you.

    Yes it does exits and the image can be viewed in Photoshop. Explorer says that the creation time was "10/10/18 02:40".


    Thursday, October 18, 2018 4:16 PM
  • Thank you very much. An awesome suggestion. I have looked into this and it's going to take me a while to get my jet-lagged brain around it as I think I'm using a slightly different version (VS Community 2017 / Win 10).
    Thursday, October 18, 2018 4:18 PM
  • Basically - yes. As per my reply to Viorel - I think it'll take me a while to get my head around how, but you've both given me something to look at. Thanks.
    Thursday, October 18, 2018 4:20 PM
  • I find it hard to believe too. Unfortunately, my account isn't verified yet and it won't allow me to attach a screen shot confirming that some of the files have different date/time in Explorer.

    How do you think an incorrect save might have occurred - so I can avoid it in the future?

    Thanks

    Thursday, October 18, 2018 4:24 PM
  • Hi

    Just to be certain. When you say 'Explorer', do you mean Windows File Explorer - Details View - Date Created, comparing with the output of your application?


    Regards Les, Livingston, Scotland

    Thursday, October 18, 2018 4:43 PM
  • I find it hard to believe too. Unfortunately, my account isn't verified yet and it won't allow me to attach a screen shot confirming that some of the files have different date/time in Explorer.

    How do you think an incorrect save might have occurred - so I can avoid it in the future?

    Thanks

    Que,

    Please use the name of the person you are responding to so we know assuming it matters. And or use the quote feature.

    Here are some things to try. Maybe you can spot something.

    Run it with the time change = 0 instead of -8 and see if you get the err. Run only the part that lists the original file name, remove code after that for subtracting 8 and etc.

    Are you running from the camera card? Copy to the hard drive first check the times.

    Remove the files with the err and see if err pops up on new files now. Run just the files with the err files now still errs?

    • Marked as answer by Queheleth Monday, October 22, 2018 10:04 PM
    • Unmarked as answer by Queheleth Monday, October 22, 2018 10:05 PM
    Thursday, October 18, 2018 6:03 PM
  • Thanks Tommy,

    (And for the tip on protocol).

    I'm running from a copy on hard drive not from the camera.

    I tried your suggestions and the error doesn't move down the list or change with removing the -8 code. I then moved a few of the dodgy files to a temporary directory and they all continue to produce the error there, so it does seem to be something to do with the files. Interestingly they're all .jpgs. 

    E:\Chris\Photos\2018-10-10 SR\Temp\111A2150.JPG    17/10/2018 09:44:02
    E:\Chris\Photos\2018-10-10 SR\Temp\111A2152.JPG    17/10/2018 09:44:05
    E:\Chris\Photos\2018-10-10 SR\Temp\111A2154.JPG    17/10/2018 09:44:12
    E:\Chris\Photos\2018-10-10 SR\Temp\111A2158.JPG    17/10/2018 09:44:18
    E:\Chris\Photos\2018-10-10 SR\Temp\111A2159.JPG    17/10/2018 09:44:21

    Friday, October 19, 2018 7:42 PM
  • Thanks Tommy,

    (And for the tip on protocol).

    I'm running from a copy on hard drive not from the camera.

    I tried your suggestions and the error doesn't move down the list or change with removing the -8 code. I then moved a few of the dodgy files to a temporary directory and they all continue to produce the error there, so it does seem to be something to do with the files. Interestingly they're all .jpgs. 

    E:\Chris\Photos\2018-10-10 SR\Temp\111A2150.JPG    17/10/2018 09:44:02
    E:\Chris\Photos\2018-10-10 SR\Temp\111A2152.JPG    17/10/2018 09:44:05
    E:\Chris\Photos\2018-10-10 SR\Temp\111A2154.JPG    17/10/2018 09:44:12
    E:\Chris\Photos\2018-10-10 SR\Temp\111A2158.JPG    17/10/2018 09:44:18
    E:\Chris\Photos\2018-10-10 SR\Temp\111A2159.JPG    17/10/2018 09:44:21

    Q,

    Seems something done by the camera to the jpgs then?

    Or when copied to the hd did the date change to the time of copy or ???

    Did you look at Viorel's comment etc?

    PS You have looked at the jpgs and they look ok? There is not some other error occurring and that resets to now?

    Friday, October 19, 2018 9:02 PM
  • Hi Tommy,

    I did look at Viorel's comment. I thought it was very helpful and could be a great work-around for my problem. I've had a preliminary look at it but I haven't managed to access the correct exif data. I need a bit more time to get my head around how to do it! 

    "Time of copy" is a very interesting suggestion. You caused my to look at the exif data in Photoshop Elements and the incorrect files have different time stamps. Photoshop shows the data in several different sections. In the "metadata" section they have the incorrect time, which does appear to be the time they were transferred - as you hinted. They also have the correct time (when taken) in the "general" data section. Whereas unaffected files have the same date in both (when taken).

    How on earth has that happened??? (I transferred the files using the Windows functionality rather than specific Canon software as I've found Windows better for separating the photos from a series of different Canon cameras.)

    Also why is Windows Explorer showing the "general" info but VB is clearly reading the "metadata"?

    • Marked as answer by Queheleth Monday, October 22, 2018 10:05 PM
    Friday, October 19, 2018 10:13 PM
  • Ug. I dont really know.

    Some things have options do it this way or that way.

    There is the metafile data that is in the image file format data. Then the windows file data which is something else.

    Here I made a copy of an old file. The  LastAccessTime is different between the original (bottom) and the copy I just made with windows file explorer (top). The copy has todays date and one has the old date.

    But, still not sure what the problem is?

    Public Class Form4
        Private Sub Form4_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim fi As New IO.FileInfo("c:\bitmaps\rusty - copy.jpg")
    
            Dim s As String
            s = fi.CreationTime & vbLf &
                    fi.LastAccessTime & vbLf &
                    fi.LastWriteTime
    
            fi = New IO.FileInfo("c:\bitmaps\rusty.jpg")
            s += vbLf & "--------------" & vbLf & vbLf
    
            s += fi.CreationTime & vbLf &
                    fi.LastAccessTime & vbLf &
                    fi.LastWriteTime
    
            MsgBox(s)
    
        End Sub
    End Class

    • Marked as answer by Queheleth Monday, October 22, 2018 10:04 PM
    Friday, October 19, 2018 11:19 PM
  • Hi Tommy,

    Thanks very much for your help. I feel I now understand what has happened even if we aren't quite sure why. I really appreciate your time and expertise.

    Best wishes,

    Q

    Monday, October 22, 2018 9:59 PM