Checking for file update

Posted on 2006-03-30
Last Modified: 2010-04-23
Hi, i have a txt can i in 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
Question by:jaxrpc
    LVL 28

    Expert Comment

    you can read Modified date and time of the file property
    LVL 44

    Assisted Solution

    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
    LVL 28

    Accepted Solution

    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

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now