LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

image file path not linking properly in executable

Solved!
Go to solution

I've got a jpeg file in a project I'm building that isn't loading when run as an executable.  The executable seems to be looking in the same directory that the image file originally was in instead of the support folder where the image is deployed.  On another machine, the exe will look for the image in the directory it was found on my machine.  When I drag the image file from the project explorer onto the block diagram, it creates a file path constant indicating where the file is located on my machine.  This doesn't seem to update when I build the exe.  The image file is included in the source files.  Any help is appreciated!

0 Kudos
Message 1 of 2
(3,102 Views)
Solution
Accepted by topic author Jeanius

A path constant is ... yes indeed constant! It does not automagically change to wherever someone might move the file too, whatever its fancy makes him do. It does not maintain a link to the actual file that it could use later to detect that the file has moved somewhere else. In fact Windows does not have such a mechanisme at all.

 

So if you want to access a file external to your application executable you have to make a correct path at runtime first. My approach is to put it in a directory relative to a VI file I put in my application. Then in that VI use the Get Current VI path, Strip the VI name from it and add the relative location to that other file to it.

 

If you do something like this:

 

project directory

      utility directory

            My Location.vi

      data directory

            MyResource.jpg

 

in the development system and then:

 

application directory

      MyApplication.exe

      data directory

            MyResource.jpg

 

in the build application.

 

With this layout it doesn't even matter if you use the old LabVIEW 8.x executable file format or the newer default format since LabVIEW 2009.

 

My Location.vi is simply a VI that takes a relative path as input (in this case "../data directory/MyResource.jpg" calls the "VI Current Path" node, uses "Strip Path" to remove the VI name, then Build Path to add the relative input path, et voila!.

Rolf Kalbermatter
My Blog
0 Kudos
Message 2 of 2
(3,091 Views)