03-04-2013 12:28 AM
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!
Solved! Go to Solution.
03-04-2013 02:12 AM - edited 03-04-2013 02:12 AM
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!.