Accessing a VI's Current Directory

Updated Oct 19, 2023

Reported In

Software

  • LabVIEW
  • LabVIEW Application Builder Module

Issue Details

I need to access my VI's current directory, and would like this behavior to be preserved when I build a stand-alone application. How can I code my VI to achieve both behaviors?

Solution

There are two different methods for accessing the VI's current directory: the Current VI's Path node and the Application Directory node. The exact returned filepaths from these two functions vary based on the environment in which they're called.
  • 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. 

    If you make a VI named Application.vi located in C:\, in the LabVIEW development environment, the Current VI's Path function will return C:\Application.vi. If you build the same VI into a stand-alone application named MyApplication.exe, then Current VI's Path will return  C:\MyApplication.exe\Application.vi.
  • The Application Directory node returns the path to the folder or directory containing the VI when called in the development environment instead of the VI itself, and when called in a stand-alone application, the VI returns the path to the folder containing the stand-alone application rather than the VI that is under that application. 

    For a VI located in C:\, the Application Directory function simply returns C:\. You must use the Build Path function to append the application or VI name to the end of the path. You would append Application.vi to access the VI on the development environment and MyApplication.exe / Application.vi to access the VI on the stand-alone application. 

Additional Information

You can use LabVIEW's Application Kind and Application Name properties to determine in which environment the VI is running. The code below shows how to use these properties to create a VI that return the current directory whether run in the development environment or in a stand-alone application.