10-28-2011 09:18 AM
I am having a problem with SetDir as well as SetCurrentDirectory (windows API).
If I use GetProjectDir to get the current project directory and append a lower folder \\DAT\ to it everything works fine (ie the path changes).
The problem occurs when I try to change the directory from that point forward.
Moving up the tree does not seem to work as well as setting SetDir to GetDir.
Solved! Go to Solution.
10-28-2011 01:59 PM
Here is my example. The path does not move up the tree.
#include "windows.h"
#include <ansi_c.h>
#include <userint.h>
#include <utility.h>
#include <formatio.h>
#include <cvirte.h>
char origpath[MAX_PATHNAME_LEN];
char newpath[MAX_PATHNAME_LEN];
int result;
int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
//LW SetDir/GetDir example
//Get project directory
result = GetProjectDir (origpath);
printf("\nGetProjectDir Result=%d",result);
//Setup newpath to <projectdir>\DAT
Fmt(newpath,"%s<%s%s",origpath,"\\DAT\\");
result = SetDir(newpath);
printf("\nSetDir Result=%d",result);
DirSelectPopup ("", "Select Directory", 1, 1, newpath);
//Set back to <projectdir>
result=SetDir(origpath);
printf("\nSetDir Result=%d",result);
//Setup newpath to <projectdir>\TST
Fmt(newpath,"%s<%s%s",origpath,"\\TST\\");
result=SetDir(newpath);
printf("\nSetDir Result=%d",result);
DirSelectPopup ("", "Select Directory", 1, 1, newpath);
//end example 1
//Windows API SetCurrentDirectory example
//Get project directory
result = GetProjectDir (origpath);
printf("\nGetProjectDir Result=%d",result);
//Setup newpath to <projectdir>\DAT
Fmt(newpath,"%s<%s%s",origpath,"\\DAT\\");
result = SetCurrentDirectory(newpath);
printf("\nSetCurrentDirectory Result=%d",result);
DirSelectPopup ("", "Select Directory", 1, 1, newpath);
//Set back to <projectdir>
result=SetCurrentDirectory(origpath);
printf("\nSetCurrentDirectory Result=%d",result);
//Setup newpath to <projectdir>\TST
Fmt(newpath,"%s<%s%s",origpath,"\\TST\\");
result=SetCurrentDirectory(newpath);
printf("\nSetCurrentDirectory Result=%d",result);
DirSelectPopup ("", "Select Directory", 1, 1, newpath);
//end example 2
return 0;
}
10-28-2011 03:49 PM
ChetK,
I looked at the code you posted and saw that the set directories are actually working as expected. The problem is with how you were testing them. The DirSelectPopup documentation says that if Default Directory is "" then it will use the current working directory. This is not always true. The first time you call any of the directory or file selection popups, if this parameter is empty, then it will use the current working directory. If the popup has been displayed before, then it will use the last directory navigated to in the previous use of a popup. That explains why your DAT directory kept showing up in the popups.
This is desired behavior for a functions to avoid a user having to renavigate to a directory with each popup, but our help documentation for this is incorrect. I have filed a bug report for this and the help should be fixed in the next release.
If you would like to display the current working directory in the popup, you will need to specify the Default Directory as such:
result = GetCurrentDirectory(MAX_PATHNAME_LEN, currentPath); DirSelectPopup (currentPath, "Select Directory", 1, 1, newpath)
10-28-2011 09:29 PM - edited 10-28-2011 09:32 PM