Hi Carlos,
I've written a similar script in the past, except mine was to backup
files and then automatically restore them if they were accidentally
deleted (I had 75 people that had to modify 1 excel document at least
once a day).
What I have done is write a script that gets a list of files from the
directory using opendir, it then does a md5_file or sha1_file hash on
the file and puts it into an array, something like $files[filename] =
hash_value, then at the end of the script it serializes the array and
writes it to a text file, then it copies the file to a backup location.
The next time the script is run it opens the text file with the hashes,
opens the directory and checks makes sure each file still exists, if it
doesn't it copies it out from the backup location. If the file does
exist it updates the hash, copies the file over again because it has
changed and ends.
You could store the file hashes in a temporary file, then compare the
hashes each time the script is run, if the hashes do not match your file
has changed and you should take whatever action you need to take.
Note that sha1_file is only available in PHP 4.3.0 and newer, md5_file
will be available in older versions of PHP as well.
Jason
On Sat, 2003-01-25 at 19:08, Carlos Fernando Scheidecker Antunes wrote:
> I would like to write a function to check if the contents of a directory, its files,
>have been changed.
> The idea is to check the directory every 2 minutes and take some actions if some
>files were updated
> or new files added.
>
> Does anyone has any ideas?
>
> I was considering listing the files (name, date modified, size) on a variable array,
>then list again and compare both arrays. In case there are different, take some
>action.
>
> Thank you,
>
> C.F.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php