We help IT Professionals succeed at work.

Checking for file update

jaxrpc
jaxrpc asked
on
Medium Priority
231 Views
Last Modified: 2010-04-23
Hi, i have a txt file....how can i in vb.net check whether it has been modified? I think it will be like a function which will check the the txt file every 1 sec and returns a boolean when it has been modified... but are there any built in functions to do that? Please point me to the right direction. thanks
Comment
Watch Question

you can read Modified date and time of the file property
TimCotteeHead of Software Services
Commented:
Hi jaxrpc,

Add this to the declarations section    
        Private watcher As FileSystemWatcher

Then in your form_load
        watcher = New FileSystemWatcher()
        watcher.Path = "c:\Myfoldertowatch"
        watcher.NotifyFilter = (NotifyFilters.LastAccess Or NotifyFilters.LastWrite Or NotifyFilters.FileName Or NotifyFilters.DirectoryName)
        watcher.Filter = "MyFileToWatchFor.txt"
        AddHandler watcher.Changed, AddressOf OnChanged
        watcher.EnableRaisingEvents = True
       
Then add the event so we can handle when it has changed.
    Private Shared Sub OnChanged(source As Object, e As FileSystemEventArgs)
        Msgbox ("The file has changed")
    End Sub    
   

Tim Cottee

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Dim selectedFile As String = FilesList.Text
        Dim FI As New FileInfo(Directory.GetCurrentDirectory & "\" & selectedFile)

        lblInfo.Text = "File Name:" & FI.Name & vbCrLf & _
                       "Length:" & FI.Length.ToString & vbCrLf & _
                       "Extension:" & FI.Extension.ToString & vbCrLf & _
                       "Creation Time:" & FI.CreationTime.ToString & vbCrLf & _
                       "Accessed:" & FI.LastAccessTime.ToString
                     
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.