Jump to content

Determine if File has Changed

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
oppo

oppo

    Newbie

  • Members
  • PipPip
  • 11 posts
I'm not sure if I will be writing this in PHP, Perl or a Shell script but I would like to do some research first. What is the best way to determine if a file has been changed? Would it be to compare the file size of a "good" version to the current version? Is there a better way?

What is HASH, wouldn't this help me in some way? Or the CRC value?

Please post your ideas!

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
A Hash is a type of index that gives you a radically different value with a small change in the object hashed. As a result, it can be an effective method for checking if a file has changed. MD5 and CRC are two commonly used hashes.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
G_Morgan

G_Morgan

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 537 posts
Can you not store the date it was last modified?

Too simple?

#4
oppo

oppo

    Newbie

  • Members
  • PipPip
  • 11 posts

G_Morgan said:

Can you not store the date it was last modified?

Too simple?

This would work but wouldn't a hash value be better??

How do you even generate a hash value on a file using any language?

#5
G_Morgan

G_Morgan

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 537 posts

oppo said:

This would work but wouldn't a hash value be better??

How do you even generate a hash value on a file using any language?

Depends. A hash value would work even if someone touched the file to update it's time stamp without modifying it's contents.

What system are you using. Unix will usually have the md5sum program installed. Call that and store the output, then call it again and compare. Note that for large files it might take a while, the time stamp will certainly be the quickest.

#6
TcM

TcM

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 11,147 posts
I would reccomend the MD5 value. Do yuo wnt to see the changes or only if the file has changed or not?