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

watch a folder

Cyril Lavy

Joined: Nov 18, 2003
Posts: 7
Is there a way to watch constantly the changes of a directory including sub-folder and then perform an action if a file has been added, deleted, modified...?
Thanks in advance!
Cyril Lavy

Joined: Nov 18, 2003
Posts: 7
...without having to scan all the subdirs and compare every file? In fact it is more some kind of process that gets the system's actions when file deleted, saved, etc...
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

Short answer: no. Java doesn't have an API for this.

[Jess in Action][AskingGoodQuestions]
Cyril Lavy

Joined: Nov 18, 2003
Posts: 7
OK! thanks...
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
A wee bit longer answer:
It wouldn't be too difficult to develop such a utility making good use of Observer and Observable, and Java Threads.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Igor Ko
Ranch Hand

Joined: Jun 24, 2002
Posts: 90
But the observer... thread need scan directory, and check each file
(by modification date, or digital digest, ....).
You alwais can write it in JNI, but it will be system dependant.
I agree. Here's the link:
subject: watch a folder
It's not a secret anymore!