File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Watch files in directory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Watch files in directory" Watch "Watch files in directory" New topic

Watch files in directory

Torben Riis

Joined: Aug 26, 2003
Posts: 3

I would like to monitor for new files or whether files has changed in directory. I know I could just make it all from the button, but does anyone know or could recommend a good framework that does the job. Maybe a framework where you can add an observer to get notifications about which file has changed?

Kind regards
Torben Riis
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
This has been asked often enough that you might find something out there. Spend some time with Google and let us know what you find.

If you decide to write something you have a couple choices. One is to write a C/C++ module that uses operating system APIs and wire that up to your Java program with JNI. It's not portable, but could be pretty cool. Another is to read the list of current files into some structure, then do it again every few minutes and compare lists to find new things. Or just comparing timestamps to the last time you ran might meet your requirements. Or not.

To list all files in a folder and all subfolders, the new DZone Snippets site has a cute File Iterator. You'll have to search around for his FlatteningIterator, too.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I agree. Here's the link:
subject: Watch files in directory
It's not a secret anymore!