• Post Reply Bookmark Topic Watch Topic
  • New Topic

file management  RSS feed

 
Maxim Katcharov
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd like to monitor a specific directory or directory subtree for changes. That is, I'd like to mirror the actual structure as nearly as possible, but also detect if a file has been replaced, etc.

I'll be using SHA1 to get the hash of each file, and while I realize that I could rehash on every startup, and from then on check the structure for any signs of change, check the hash if a file has been moved down a dir in the tree, etc, I was hoping there would be a better way.

Is it possible to be notified of a directories changes? (And also, which and to where a file was moved?)
 
Petr Blahos
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Maxim,

Some operating systems may provide some sort of file/directory
change notification, but generally not and definitely not
with pure java.

It is not impossible though. Antiviruses do it.

Best regards,
Petr
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see why you would have to open and read each file, as long as the date last modified is correctly maintained. Why not combine the timestamp and length - which you can get without opening the file - to create your hash.
Bill
 
Maxim Katcharov
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll have to generate the the hash regardless, but some of the files would get rather big so the process is best avoided. Perhaps saving the state (size, name, date, and perhaps some sort of quick hash) of the directory and checking every two seconds...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!