• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • Last Modified:

Checking for file update

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
0
jaxrpc
Asked:
jaxrpc
  • 2
2 Solutions
 
iboutchkineCommented:
you can read Modified date and time of the file property
0
 
TimCotteeCommented:
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
0
 
iboutchkineCommented:
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
                     
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now