I need to detect when a change is made to a directory (new file, etc). I did this a few years ago but, over the years, have lost track of my code and don't seem to be able to find a starting point.
If your program handle directory in linux or unix, the last modified date can tell you if there is change in that directory.
If your program is for Windows, I recommend you read all files among the directory and subdirectory of your target directory.
The following is the detail:
Assume the target directory c:\adirectory
You can create a dao for storing last modified time, complete file path, isDirectory flag.
After every 10 minutes, you read all the directories, subdirectories, files one by one. use dao to store the detail
for each file or directory.
you create a dao for c:\adirectory
last modified time=xxxxxxx
complete file path=c:\adirectory
isDirectory=false
then you can use this dao to hastable with index "c:\adirectory"
After another 10 minutes, you can read all directories, subdirectories and files again. And you can search in hastable if every file or directory appear in the hastable created in previous 10 minutes.
After you have compared every entry in the current hastable and
mail to user there is changed,
previousHastable =
deep clone of currentHastable
and your program can sleep for ten minutes.
Thread.sleep(xxxxx)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.