From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

CopyFile and LoadPanel Relative Paths

Solved!
Go to solution

I am in the process of moving large projects into a Subversion repo.

 

Currently my code has calls such as

CopyFile(SourceFileName, TargetFileName);

where SourceFileName and Target File Name are of the form S:\Absolute\Path\To\A\File.extension.

I want to be able to get rid of absolute paths, so that it doesn't matter where my teammates decide to checkout my Repo to on their machines.

So ideally SourceFileName would be of the form ..\..\Relative\Path\To\File.extension

 

Does the LabWindows CopyFile function from the Utility Library (utility.h) support relative paths? If so, what are they relative to? The location of the .c file where I call them? The .prj file? The directory where the .exe will be run from?

 

Also for the LoadPanel (int parentPanelHandle, char filename[], int panelResourceID) function from the User Interface Library (userint.h) can I use a relative path for the filename parameter? And what is it relative to?

I know it works if filename is an C:\absolute\path\to\file.uir, and I have seen code where filename is simply "file.uir" (where does LabWindows look for this file?). Can I make the filename "..\..\Path\to\file.uir"? And again, what is this relative to?

 

Last, and most importantly, If I have included "file.uir" in the project tree (so that I can see it in the .prj file), then will labwindows know where to find it if I just use "file.uir" in my call to LoadPanel ?

 

A lot of questions, I know, but I would really appreciate any help! Thank you!

and

0 Kudos
Message 1 of 5
(2,592 Views)
Solution
Accepted by topic author ChrisWatson

Good news for you!

CopyFile and LoadPanel both support relative path addressing. And it is relative to whatever is returned by GetProjectDir.

 

You don't need to add the UIR file(s) to the project to be able to load it with LoadPanel. If you give only a file name, then it is searched in the project directory. Otherwise an absolute or relative path is required.

 

Hope this helps,

S. Eren BALCI
IMESTEK
Message 2 of 5
(2,563 Views)

First of all, the easy answer Smiley Wink

As can be read in the help for the function

If the name is a simple filename that contains no directory path, the file is loaded from the directory that contains the executable.

 

From this assuption on more complex scenarios can be elaborated, for example a subfolder of the application directory where to store .UIR files or another folder. In both cases, you must embed the path both in the call to LoadPanel and in the #include for the .h file in this form:

 

Subfolder

#include "Subfolder\\Panels.h"

tmpH = LoadPanel (0, "Subfolder\\Panels.uir", PANEL);

 

A relative folder

#include "..\\Panels\\Panels.h"
tmpH = LoadPanel (0, "..\\Panels\\Panels.uir", PANEL);

 

(Note the double backslash needed to avoid C to consider '\P' as an escape character)



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 3 of 5
(2,560 Views)

Thank you for the response! After reading Roberto's answer I am looking at ebalci's again:

 

@ebalci wrote:

 

CopyFile and LoadPanel both support relative path addressing. And it is relative to whatever is returned by GetProjectDir.


Now I am confused. Roberto's response (and the documentation) says the paths are relative to the directory of the .exe. But GetProjectDir gives you where the .prj lives. Couldn't that be different from where the .exe lives?

 

So am I correct that if I make things relative to GetProjectDir (or use MakePathName and GetProjectDir to make my paths) it would not work if my .exe does not live in the same directory as my .prj?

 

Is my best course of action to tell my teammates they need to set their build configurations so that their .exe has the location relative to the .uir files that is expected by our source code?

 

Thanks

0 Kudos
Message 4 of 5
(2,537 Views)

The term "project" is used in a loose sense in this function's name.

 

Here is the function description:

Gets the name of the directory that contains the currently loaded project file.

You can use GetProjectDir when you distribute a project and its related files to multiple users who might place the files in a different directory on each computer. If your program needs to access a file that is in the same directory as the project, you can use GetProjectDir and MakePathname to construct the full pathname.

 

In a stand-alone executable, the function obtains the directory containing the executable file.

S. Eren BALCI
IMESTEK
Message 5 of 5
(2,532 Views)