Error 5: “LabVIEW: File already open” when Writing, Deleting or Replacing File

Updated Aug 21, 2023

Reported In

Software

  • LabVIEW

Issue Details

  • I am trying to use File I/O VIs in LabVIEW to write to, delete or replace a file, but when I run the code, a VI returns Error 5 – “LabVIEW: File already open”. What can I do to resolve this issue?
  • I am trying to use the Report Generation Toolkit in LabVIEW, but I keep receiving Error 5. How can I fix this?

Solution

Follow the steps below to resolve the issue:
  • If you have another application that is reserving your file (like backup applications, NI DataFinder, or desktop search applications):
    • Add error handling to retry the file operation when Error 5 occurs.
    • Disable the offending application.
  • If you are trying to perform multiple, simultaneous file writes on the same file within your LabVIEW VI either:
    • Serialize the operation.
    • Use an asynchronous File I/O API (like the TDMS Advanced API)
  • If using the Application Builder:
    • Try cleaning the build directory and then rebuilding your application. In the project, right-click on Build Specification»Clean.
    • Try changing the location of the build directory.

Additional Information

Error 5 is generated when a LabVIEW File I/O VI is unable to open a reference to an existing file because another process already has an open reference to the file. This can occur if LabVIEW, another application, or your operating system has already opened the file for writing.

Error 5 is not guaranteed to be thrown in the event that a file is already open and should not be relied upon as a method of preventing race conditions or as a method of controlling file access.