10-25-2012 04:30 PM
I have the following questions about paths.
1. For LabVIEW version newer than 8.x, the path for a vi that is compiled into an exe is preserved. I understand that it will prevent naming conflict inside the exe. However, it is a pain to do build path and strip path. Is there a better way? I find myself having the LabVIEW 8.x file layout checked a lot of times when I complied an exe.
2. It seems like the Current VI's Path node is always preferred over the Application Directory node. Is there an instant where it is better to use the Application Directory node?
3. Are there any strategy to keep build and strip path from getting out of control? Some codes use so many build and strip path, and they make it very hard to tell what folder is being accessed.
4. When would you use a relative path over an absolute path or vice versa?
10-26-2012 04:26 AM - edited 10-26-2012 04:27 AM
In 95% of all cases, i use "Application Directory".
Most obvious reason: I call sources located outside of the EXE, so i don't have to distinct between the application being compiled into an EXE or if i still work on development.
In the rest of all cases (5%), i will "stay" in my EXE. So i take "Current VI path", strip the name and maybe one or two paths, then add the new relative path. I never use this "to leave the EXE", so the sources are (if organized in a well structured project folder) equally placed in development as in EXE. So, here as well, i have not to distinct between EXE or development.
If having to distinct EXE from development, you can use "Application Kind" (App.Kind) in VI Server to check for the environment:
Norbert
EDIT: Relative paths are always superior to absolut paths except if you have to change the drive/partition.
10-26-2012 07:35 AM
I will second pretty much everything Norbert said.
1. Use the newer format. It works better when trying to dynamically call VIs.
2. I use the Application Directory so much more than the Current VIs Path, mostly because I'm trying to find a lookup table or the like.
3. One trick is to use ".." in your build path. Using ".." as a folder will move up a folder. So you can do some fun stuff with that. For instance, application path is "C:\foo\bar\blah". You can use "..\blah1" in the relative path and the result will be "C:\foo\bar\blah1".
4. 99% of the time, I use relative paths simply because projects get moved around.
10-26-2012 08:56 AM
Microsoft have been trying to encourage developers to separate program files, user files, and program data files since Windows XP. In Vista they began to mildly enforce it; depending on whether the program is being run by an administrator or as a standard user, the program may not be allowed to write to the Program Files directory.
I almost always use the Get System Directory VI, which will correctly resolve the path depending on the system it is running on. i.e. Win XP, Win 7, MacOS, Linux etc.
10-26-2012 09:16 AM
Norbert,
You said that you take "Current VI path", strip the name and maybe one or two paths, then add the new relative path. I never use this "to leave the EXE",
Why do you need to strip the path from currenet VI path if you don't use current vi path to leave the exe? It seems to me that the two statements conflict.
10-26-2012 09:18 AM
Crossrulz,
How is the newer format better when trying to dynamically call VIs?
10-26-2012 09:21 AM
@jyang72211 wrote:
Norbert,
You said that you take "Current VI path", strip the name and maybe one or two paths, then add the new relative path. I never use this "to leave the EXE",
Why do you need to strip the path from currenet VI path if you don't use current vi path to leave the exe? It seems to me that the two statements conflict.
I sometimes require to strip a "folder" or two from current VIs path because the VI is in a subfolder within the project. Since the EXE keeps that subfolder, navigation between subfolders in the EXE require strip path.
But i never go that high by stripping that i strip the name of the EXE....
Norbert
10-26-2012 09:25 AM
Oh, I was confused. I kept thinking about the file layout of an exe for 8.x. For the new LabVIEW version, it makes perfect sense.
10-26-2012 09:28 AM
@jyang72211 wrote:
Crossrulz,
How is the newer format better when trying to dynamically call VIs?
Because the newer format keeps the directory structure (to a degree) inside of the EXE. Therefore any relative paths between VIs will not change between the development and run time environments.
10-26-2012 09:32 AM
Oh, I didn't realise we were navigating around inside the EXE. To amend my post:
- I will use relative paths within the EXE, for example to read dynamic VIs that were shipped in the main build.
- Almost anything that involves writing to file is resolved through the Get System Directory VI
- Additional resources like plug-ins are saved to the Application Data Directory, again read with the Get System Directory VI