Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. File write times in .NET local drive vs. NAS drive

File write times in .NET local drive vs. NAS drive

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharpvisual-studiosysadminquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MikeAngel
    wrote on last edited by
    #1

    Hi, I'm trying do write a backup program in VB .NET. It needs to avoid backing up files that have already been backed up and so it compares the last write times of the source and backup files. If they are the same, the backup for the file is not performed. If both the source file the backup file are on the local hard drive, the comparisons work correctly. If both the source file the backup file are on a Network Attached Storage drive, the comparisons work correctly. But if the source file is on the local hard drive and the backup file is on the Network Attached Storage drive, the comparison always says the they are different no matter what. Code: (I'm using the CompareTo method.) Dim SourceHasLaterDate As Int16 = SourceWriteTime.CompareTo(BackupWriteTime) Is there any way I can get an accurate result for the third condition? Thanks, Mike PS: I'm modifying the backup program written by Taner Riffit.

    L 1 Reply Last reply
    0
    • M MikeAngel

      Hi, I'm trying do write a backup program in VB .NET. It needs to avoid backing up files that have already been backed up and so it compares the last write times of the source and backup files. If they are the same, the backup for the file is not performed. If both the source file the backup file are on the local hard drive, the comparisons work correctly. If both the source file the backup file are on a Network Attached Storage drive, the comparisons work correctly. But if the source file is on the local hard drive and the backup file is on the Network Attached Storage drive, the comparison always says the they are different no matter what. Code: (I'm using the CompareTo method.) Dim SourceHasLaterDate As Int16 = SourceWriteTime.CompareTo(BackupWriteTime) Is there any way I can get an accurate result for the third condition? Thanks, Mike PS: I'm modifying the backup program written by Taner Riffit.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      there are a couple of reasons why two DateTimes that should be equal actually can be different, here are the most important ones: - some file systems only have a resolution of 2 seconds (long ago the date was stored in 16-bit, and the time in another 16-bit number (5-bit for the hour, 6-bit for the minutes, and 5 rather than 6 for the seconds). - some file systems have a different way of dealing with daylight savings time (should the correction be applied dynamically, or should the corrected time be stored in the directory information?). When I created my backup/synchronize utility years ago, I ended up comparing DateTimes with a tolerance: any pair of DateTime values that differed by -1, 0 or 1 hour give or take -2 to +2 seconds, I consider identical. And yes, that could lead to false identicals, but since I also compare file size and file name, chances are slim. :)

      Luc Pattyn [My Articles] Nil Volentibus Arduum

      M 1 Reply Last reply
      0
      • L Luc Pattyn

        there are a couple of reasons why two DateTimes that should be equal actually can be different, here are the most important ones: - some file systems only have a resolution of 2 seconds (long ago the date was stored in 16-bit, and the time in another 16-bit number (5-bit for the hour, 6-bit for the minutes, and 5 rather than 6 for the seconds). - some file systems have a different way of dealing with daylight savings time (should the correction be applied dynamically, or should the corrected time be stored in the directory information?). When I created my backup/synchronize utility years ago, I ended up comparing DateTimes with a tolerance: any pair of DateTime values that differed by -1, 0 or 1 hour give or take -2 to +2 seconds, I consider identical. And yes, that could lead to false identicals, but since I also compare file size and file name, chances are slim. :)

        Luc Pattyn [My Articles] Nil Volentibus Arduum

        M Offline
        M Offline
        MikeAngel
        wrote on last edited by
        #3

        When I compensate for the differences in the storage devices by converting the last write date/time results to concatenated strings containing Year, Month, Day, Hour, and Second, the comparison works properly. With this approach I'm assuming that going to the second is accurate enough. You may want to use the same approach with yours. Thanks for the explanation. Here is my code:

        Dim SourceWriteTime As DateTime = CDate(File.GetLastWriteTimeUtc(SourceFileName))
        With SourceWriteTime
        Test1 = .Year & "/" & .Month & "/" & .Day & "/" & .Hour & "/" & .Minute & "/" & .Second
        End With

        Dim BackupWriteTime As DateTime = CDate(File.GetLastWriteTimeUtc(BackupFileName))
        With BackupWriteTime
        Test2 = .Year & "/" & .Month & "/" & .Day & "/" & .Hour & "/" & .Minute & "/" & .Second
        End With
        Dim SourceHasLaterDate As Int16 = Test1.CompareTo(Test2)

        If the SourceHasLaterDate > zero, I backup the file.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups