This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "watch a folder" Watch "watch a folder" New topic
Author

watch a folder

Cyril Lavy
Greenhorn

Joined: Nov 18, 2003
Posts: 7
Hello,
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
Greenhorn

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
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

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


[Jess in Action][AskingGoodQuestions]
Cyril Lavy
Greenhorn

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

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.
 
Don't get me started about those stupid light bulbs.
 
subject: watch a folder
 
Similar Threads
My suggestion
WA #1.....word association
WAR file doubt
constant lookup for folder changes
5 letter scrabble