LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

CVI Working Directory problem

Solved!
Go to solution

I'm runing a program compiled in CVI 8.5 that is giving me a random problem.

The Function GetDir(gExecFolder) Doesn't Return the same value all the time, which creates an error when accessing files that Do Not have a full path.

 

e.g. MyFunction("FileName.ext");

 

The error is File Not Found.

 

Please take a look at these 2 images showing the different outputs of GetDir(gExecFolder).

 

Good Output:

getdir_output_ok.jpg

 

Bad Output:

getdir_output_NotOk.jpg

 

Note that I stopped the execution after this line executed.

 

Thanks for your help.

0 Kudos
Message 1 of 5
(5,273 Views)
Solution
Accepted by topic author skykeeper

I personally resolved to have fixed pathnames wherever possible as the current working directory is not always constant throughout the live of the application. As an example, it is changed when you are browsing the PC with FileSelectPopup or DirSelectPopup: I normally have a timer or a secondary thread that periodically saves working status on disk, so it is executed even when the popup is on and I have been getting errors for non existing file due to the changed working directory.

 

An alternative to GetDir is to use GetProjectDir that returns the EXE (or PRJ) directory in every condition.



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?
0 Kudos
Message 2 of 5
(5,250 Views)

Still having same problem in 2020 with CVI2017 😞

Thank you GetProjectDir() solved my problem.

0 Kudos
Message 3 of 5
(3,485 Views)

@jabara80 wrote:

Still having same problem in 2020 with CVI2017 😞


It’s unfixable! The concept of a current directory per process works fairly ok in a command line application but falls flat on its face in GUI applications. And Microsoft made it worse by automagically updating the current directory whenever any file dialog is positively acknowledged by the user with the directory of the selected file. 
Relative paths are evil for all functions that rely on the current directory to resolve such paths and that is by definition all C runtime library functions unless explicitly stated otherwise. Many CVI library functions inherited that legacy and now can’t be changed anymore as that would break compatibility.

When I write C code for file operations I usually check passed in file paths to be absolute and refuse them otherwise as resolution to current dir is normally a disaster waiting to happen rather sooner than later!

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 4 of 5
(3,457 Views)

Thank you Rolf, now I understand the reason.  I will follow your recommendation.

 

0 Kudos
Message 5 of 5
(3,431 Views)