• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

reporting changes (help please!)

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

After creating a small program that lists files, how would I go about craeting a process that scans the directory for changes and reports them. The lastModified() method just shows the date and time of last modification. There must be a more efficient way to do this, right?
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you're right on track with listing the files and examining the lastModified() time. For recent changes, compare last modified to whatever you define as "recent" or the last time you ran.
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In terms of efficiency, I don't think there's any way to make this operation any faster than O(n).

In terms of implementation, I think it might turn out a bit tedious to keep track of all the last modified dates for all the files -- especially if you have a lot of files.

Instead, try generating a hash for all the files within a directory (recursive operation). This way you only have to keep track of one number, as opposed to possibly thousands of last modified dates. If the hashes don't match that means something has changed.
 
Oh the stink of it! Smell my tiny ad!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic