This content is not available in your preferred language.

The content is shown in another available language. Your browser may include features that can help translate the text.

Error 7 in Executable When Using the Current VI's Path Constant

Updated Oct 19, 2023

Reported In

Software

  • LabVIEW Application Builder Module
  • LabVIEW

Issue Details

I'm using the Current VI's Path constant and stripping off the VI name in order to access the owning directory. This works in the development environment, but when I build my VI into an executable I am having some problems, including, but not limited to receiving Error 7 occurred at New File

How do I build my VI to avoid changes when deploying it as an executable?

Solution

The issue can be addressed by the following:

  • In LabVIEW versions 2009 and later, you can use the Application Directory VI.

Note: If you call this VI from a stand-alone application, this VI returns the path to the folder containing the stand-alone application.  If you call this VI from the development environment and the VI is loaded in a LabVIEW project file (.lvproj), this VI returns the path to the folder containing the project file. If the project is not saved, this VI returns <Not a Path>.  If the top-level VI is not loaded in a project, the VI returns the path to the directory containing the top level VI. If the VI is not saved to disk, this VI returns <Not a Path>.
 

  • For LabVIEW versions prior to 2009, you can use an application property node to programmatically determine in which environment you are running, and based on that strip the path either once or twice. In the screenshot below you can see how to accomplish this.

  • Another option is to use the Application Directory property node in order to find the running directory of an executable.

Note: the leftmost VI is Open Application Reference, not Open VI Reference. Also, since this property searches for running LabVIEW executables, during development this property returns the path to your current instance of LabVIEW.

 

Additional Information

The Current VI's Path node returns the full path including the VI's name. This path varies based on whether the VI is running in the LabVIEW development environment or in a stand-alone application. LabVIEW wraps all VIs associated with a stand-alone application into an extra layer, which is actually the executable itself.

Consider a VI named Application.vi located in the hard drive's root directory (e.g. C:\). In the LabVIEW development environment, the Current VI's Path function returns: 

C:\Application.vi 

Now consider the same VI built into a stand-alone application named MyApplication.exe. When running, the current VI's path function returns: 

C:\MyApplication.exe\Application.vi

As you can see from the different file paths above, you need to strip the path's differently depending on whether you are running in the development environment or on a stand-alone executable. 

A more manual approach to the issue is to search the path for .exe. If it is not present in the path, you only need to strip the path once to get the owning directory. If it is present in the path, you must strip the path twice to return the owning directory.