Results 1 to 40 of 41

Thread: Daylight Saving nightmare

Threaded View

  1. #1

    Thread Starter
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Daylight Saving nightmare

    This isn't really a VB6 issue, but I need to overcome it for an incremental backup I run (weekly) to various flash drives. Quick background:

    My backup program is designed to support three different flash drives of three different sizes (because that's what I personally have): 2 GB, 32 GB and 128 GB. During the folder recursion, I include logic to NoRecurse some paths, exclude some subfolders, and pick and choose which flash drive(s) any given folder tree is sent to. I've stripped out this logic for the code posted here.

    I just now noticed that all of a sudden my larger (80 GB) backup shows every single file as out of sync. Obviously I didn't change all 17,000+ files in the past few hours; I see the reason is because Daylight Saving just kicked in around four hours ago.

    Here's a stripped down version of the recursion logic I'm using:

    vb Code:
    1. Private Type FILETIME
    2.     dwLowDateTime As Long
    3.     dwHighDateTime As Long
    4. End Type
    5.  
    6. Private Type SYSTEMTIME
    7.     wYear As Integer
    8.     wMonth As Integer
    9.     wDayOfWeek As Integer
    10.     wDay As Integer
    11.     wHour As Integer
    12.     wMinute As Integer
    13.     wSecond As Integer
    14.     wMilliseconds As Long
    15. End Type
    16.  
    17. Private Const MAX_PATH  As Long = 260
    18.  
    19. Private Type WIN32_FIND_DATA
    20.     dwFileAttributes As Long
    21.     ftCreationTime As FILETIME
    22.     ftLastAccessTime As FILETIME
    23.     ftLastWriteTime As FILETIME
    24.     nFileSizeHigh As Long
    25.     nFileSizeLow As Long
    26.     dwReserved0 As Long
    27.     dwReserved1 As Long
    28.     cFileName As String * MAX_PATH
    29.     cAlternate As String * 14
    30. End Type
    31.  
    32. Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
    33. Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
    34. Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
    35. Private Declare Function FileTimeToLocalFileTime Lib "kernel32" (lpFileTime As FILETIME, lpLocalFileTime As FILETIME) As Long
    36. Private Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As Long
    37.  
    38. ' My data structure, as opposed to API call structures
    39. Private Type FileType
    40.     Group As Long
    41.     Folder As String
    42.     FileName As String
    43.     FileDate As Date
    44.     FileSize As Currency
    45.     Flags As Long
    46. End Type
    47.  
    48. Private Sub AddFolder(ByVal pstrFolder As String)
    49.     Const MAXDWORD = &HFFFF
    50.     Const INVALID_HANDLE_VALUE = -1
    51.     Dim strPath As String
    52.     Dim strFile As String
    53.     Dim lngHandle As Long
    54.     Dim intSearching As Integer
    55.     Dim typFile As FileType
    56.     Dim typFind As WIN32_FIND_DATA
    57.  
    58.     intSearching = 1
    59.     lngHandle = FindFirstFile(pstrFolder & "\*.*", typFind)
    60.     Do While lngHandle <> INVALID_HANDLE_VALUE And intSearching <> 0
    61.         strFile = Left$(typFind.cFileName, InStr(typFind.cFileName, vbNullChar) - 1)
    62.         If (typFind.dwFileAttributes And vbDirectory) = vbDirectory Then
    63.             If Left$(strFile, 1) <> "." Then AddFolder pstrFolder & "\" & strFile
    64.         Else
    65.             Select Case strFile
    66.                 Case "desktop.ini"
    67.                 Case Else
    68.                     With typFile
    69.                         .Group = mlngGroup
    70.                         .Folder = Mid$(pstrFolder, Len(mstrPrefix) + 1)
    71.                         .FileName = strFile
    72.                         .FileDate = StructureToDate(typFind.ftLastWriteTime)
    73.                         .FileSize = CCur((typFind.nFileSizeHigh * MAXDWORD) + typFind.nFileSizeLow)
    74.                     End With
    75.                     AddFile typFile
    76.             End Select
    77.         End If
    78.         intSearching = FindNextFile(lngHandle, typFind)
    79.     Loop
    80.     lngHandle = FindClose(lngHandle)
    81. End Sub
    82.  
    83. Private Function StructureToDate(ptyp As FILETIME) As Date
    84.     Dim typLocal As FILETIME
    85.     Dim typSystem As SYSTEMTIME
    86.  
    87.     If FileTimeToLocalFileTime(ptyp, typLocal) = 1 Then
    88.         If FileTimeToSystemTime(typLocal, typSystem) = 1 Then
    89.             With typSystem
    90.                 StructureToDate = DateSerial(.wYear, .wMonth, .wDay) + TimeSerial(.wHour, .wMinute, .wSecond)
    91.             End With
    92.         End If
    93.     End If
    94. End Function
    95.  
    96. ' This is the actual function I use, which includes references and data structures not included in this post
    97. Private Sub AddFile(ptypFile As FileType, plngSource As Long)
    98.     Dim lngMax As Long
    99.     Dim i As Long
    100.    
    101.     With mtypDrive(plngSource)
    102.         .Current = .Current + 1
    103.         If .Current > .Files Then
    104.             .Files = (.Files * 5) \ 4
    105.             ReDim Preserve .File(1 To .Files)
    106.         End If
    107.         .File(.Current) = ptypFile
    108.     End With
    109. End Sub

    This code correctly returns all file dates exactly like explorer shows them. Unfortunately, explorer seems to be randomly making up dates for my old haven't-touched-them-in-years files like my wallpapers.

    Click the thumbnail for a comparison of the files on my hard drive vs the files I manually copied over to my Sansa Extreme 128 GB flash drive (bought on Amazon, link) a couple weeks ago:



    Any ideas for how I can get proper, unchanging file dates? This is just for me on my personal computer, so any solution that works is a possibility.

    For example, would it help to turn off system DST and just adjust the time manually? (Many of those unchanged files have crazy datetime changes on them, much more radical than a single hour off. Up to 9 days wrong!)
    Last edited by Ellis Dee; Mar 13th, 2016 at 06:18 AM.

Posting Permissions

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



Click Here to Expand Forum to Full Width