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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows File Table

Status
Not open for further replies.

swade61970

Programmer
Apr 2, 2003
19
US
I need to write a program that can run as a service. The program needs to monitor a server for when files gets created. I can write a program to run file system commands in VB to look for files created since the last time the program ran but I was hoping there is a faster approach.

The server where the files reside will have approximately 80 folders with an unlimited number of files in each folder. I just want to know when a new file has been created in each of the folders.

Is there an API I call that can read a Windows Database that contains the list of files and the time and date they were created?

Any other suggestions?
 
Check out the filesystemwatcher class.

Sample
Code:
Dim watcher As New FileSystemWatcher()
watcher.Path = "c:\temp\"
' Watch for changes in LastAccess and LastWrite times, and
' the renaming of files or directories. 
watcher.NotifyFilter = (NotifyFilters.LastAccess Or NotifyFilters.LastWrite Or NotifyFilters.FileName Or NotifyFilters.DirectoryName)
' Only watch text files.
watcher.Filter = "*.txt"
        
' Add event handlers.
AddHandler watcher.Changed, AddressOf OnChanged
AddHandler watcher.Created, AddressOf OnChanged
AddHandler watcher.Deleted, AddressOf OnChanged
AddHandler watcher.Renamed, AddressOf OnRenamed


Sweep
...if it works dont mess with it
 
Works great. How do you get the event handler to stop trigger ing? It keeps on firing after creating one file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top