LabWindows/CVI

取消
显示结果 
搜索替代 
您的意思是: 

SetDir Problem

已解决!
转到解答

 

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.

 

0 项奖励
1 条消息(共 4 条)
3,578 次查看

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;
}

0 项奖励
2 条消息(共 4 条)
3,563 次查看
解答
已被主题作者 ChetK 接受

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)

 

 

National Instruments
3 条消息(共 4 条)
3,552 次查看

Thank you,

破坏者
破坏者
眨眼表情

 

 

-Chet

0 项奖励
4 条消息(共 4 条)
3,545 次查看