Results 1 to 9 of 9

Thread: [RESOLVED] determine if file changed

  1. #1

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Resolved [RESOLVED] determine if file changed

    I am trying to create a file backup, but only want to overwrite files that have changed
    How can i do this without using FSO ?
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  2. #2
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: determine if file changed

    This is what the Archive attribute was for.

    XXCOPY TECHNICAL BULLETIN #06 offers one explanation.

  3. #3
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: determine if file changed

    The best way would be to generate a checksum value for each file, then check the checksum against the current file's checksum and see if they match...if not, they've changed.

    Dilettante's suggestion, while the standard method, is open to outside intervention...meaning that some files might not be backed up when you run your backup code.

    And regarding checksums (in case you need to ask), anything will do...CRC32 is usually what people use and more than enough, but MD5 is the best option...and there's free functions out there for calculating both :-)
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  4. #4

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: determine if file changed

    Thanks guys found this little function that seems to do what i need:
    Code:
    Public Function FileUpToDate(sPath As String, sDest As String) As Boolean
    Dim a, b, c As Variant
    FileUpToDate = Len(Dir$(sPath)) > 0
    If FileUpToDate = False Then Exit Function
    'Already False if not exist so just exit
    'Here is where I need more code to compare file Tmie/Dates
    a = FileDateTime(sPath)
    b = FileDateTime(sDest)
    c = DateDiff("s", a, b)
    If c < 0 Then FileUpToDate = False Else FileUpToDate = True
    
    End Function
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  5. #5
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: determine if file changed

    The code you found will work, and won't need you to keep any data about each file, but my suggestion's still the best :-)
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  6. #6
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: determine if file changed

    Quote Originally Posted by smUX
    The code you found will work, and won't need you to keep any data about each file, but my suggestion's still the best :-)
    LOL!
    Why your suggestion's still the best while other way works and "won't need you to keep any data about each file"?
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  7. #7
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: determine if file changed

    Quote Originally Posted by anhn
    Why your suggestion's still the best while other way works and "won't need you to keep any data about each file"?
    1) The archive bit of a file is not limited to the one program, any can change it

    2) The date is not a 100% reliable way of checking which file is the newer...all it takes is a clock to be wrong somewhere and it ruins the whole thing

    3) Checksum is the only 100% reliable way of checking to see if a file has changed...although the date *may* be considered reliable enough as the likelihood of it going wrong is low
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  8. #8
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: determine if file changed

    No way is 100% reliable.
    Not everyone can change "the archive bit" of a file.
    If everyone can change it then it is no longer 100% reliable.

    If "although the date *may* be considered reliable enough as the likelihood of it going wrong is low" then why not use that?

    Respect your "professinal way of using CRC" but you should not say "but my suggestion's still the best". I will never use that "best" suggestion.
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  9. #9
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: [RESOLVED] determine if file changed

    It's the best because it's the most reliable, and yes it is the closest to 100% reliable (as you said, nothing is 100% reliable, there is a chance of two CRCs being the same, but there's more chance of me winning the lottery every week without ever playing even once :-)) but it does have the overhead of having to store the CRC data for each file which may be too much of an overhead :-)

    It's your choice to "never use that best suggestion", just as it's my choice to suggest it :-P
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

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