09-24-2009 03:50 PM
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:
Bad Output:
Note that I stopped the execution after this line executed.
Thanks for your help.
Solved! Go to Solution.
09-25-2009 02:28 AM
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.
03-11-2020 05:45 PM
Still having same problem in 2020 with CVI2017 😞
Thank you GetProjectDir() solved my problem.
03-14-2020 05:37 AM
@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!
03-15-2020 05:30 PM
Thank you Rolf, now I understand the reason. I will follow your recommendation.