LabWindows/CVI User Group Documents

cancel
Showing results for 
Search instead for 
Did you mean: 

Monitoring file changes

Overview

Ever wanted to know in your program when a specific file has changed?

If yes, then this sample program is the solution to your needs: it sits silent waiting for a system notification about changes.

Description

This sample program lets you select a file to monitor and installs a listener that waits for system notifications about changes in the folder the file is in; it then checks for date and time of last update and displays new content on screen if the file has changed.

The example program has been developed to handle text files simply to have a visual effect of how it operates, nevertheless it can handle every type of file since what to do after receiving the notification is left to the programmer.

By relying on a system notification, the application consumes very little resources since it does really nothing but waiting for the notification to arrive. A timeout is provided to let the system responsive to user interaction.

The notification is handled by a separate thread to let the main program thread unaffected.

How to run this example

  1. Download the attached sample program
  2. Create the sample file you want to monitor: the program points by default to c:\temp\MyFile.txt but you can change this at runtime simply selecting a new folder and file. The default folder and file names can be changed editing Monitor.cfg file
  3. Run the example and press Start control button: initial file content will be displayed on screen. This is the program window:
    Screenshot 2016-01-11 13.02.05.png
  4. Open the text file, change its content and save it (you do not need to close the file: simply save it)
  5. The program will receive the notification and display the updated file content on screen
  6. In case of errors, Errors found checkbox will be marked: pressing the question mark will display the program error log

How to integrate the code in your application

All the code needed for this facility is located in ThreadNotify () function and can be copied in your code with the adaptations needed to accomodate it to the code structure. The section that displays file content on screen must be changed to the desired reaction to the event.



Requirements

Software

This program has been developed in LabWindows/CVI 2012SP1 Full Development System

It relies on some system APIs to work so the interface to the Win32 API must be installed.

According to this document (WARNING: it may take a *long* time to open!) the APIs used are available in every CVI version so it should be possible to run the example in base version too, however I cannot test it since I only have FDS.

Hardware

No hardware is required to run this example



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Contributors