LabWindows™/CVI™ to Programmatically Check File or Directory Existence

Updated Jan 12, 2023



  • LabWindows/CVI

How can I programmatically check if a file or directory exists using LabWindows/CVI?

  1. Using native LabWindows/CVI commands or C language commands, you can check if a file or directory exists.  You can use one of the following methods: The FileExists LabWindows/CVI function determines if a file or directory with the specified pathname exists on disk. The function is located in the Programmer's Toolbox which is included with LabWindows/CVI 6.0 and higher. To load the Programmer's Toolbox:
  • Open a LabWindows/CVI project and go to Instrument » Load.
  • From the Load Instrument window, select toolbox.fp from the C:\Program Files\National Instruments\MeasurementStudio\CVI\toolslib\toolbox\ folder. This will load the Programmer's Toolbox and return you to the LabWindows/CVI project window.
  • Access the FileExists function from Programmer's Toolbox » File » FileExists.
FileExists returns 1 (TRUE) if the file exists, 0 (FALSE) if the file was not found, and a negative user interface library error code if an error occurred.
  1. The OpenFile function can be used to determine if a file exists. The function returns a file handle of type interger which you can use to determine whether or not a file actually exists. If the file does not exist, then the file handle will be negative. Additionally, when OpenFile does not find a specified file, LabWindows/CVI will display a window indicating that it has encountered a non-fatal run-time error. To prevent the error window from appearing, you can disable the library errors by deselecting library errors on the Run menu: Run » Break-on » Library Errors.
  2. The fopen C function will act similarly to the OpenFile function described above, and it can be used in place of OpenFile if you prefer.