Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Directory Listener

Status
Not open for further replies.

lordgeek

Programmer
May 20, 2006
2
0
0
US
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)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top