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

Updated Oct 19, 2018

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?

Solution

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 in the event of error 5
    • 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 Application Builder:
    • Try cleaning the build directory and then rebuilding your application. I.e. In the project, right-click on the 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.

WAS THIS ARTICLE HELPFUL?

Not Helpful