LabWindows/CVI

Content Type
Programming Language
Current manual

GetProjectDir

GetProjectDir

int GetProjectDir (char directoryName[]);

Purpose

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.

Example Code

/* Get the name of the directory that contains myfile.dat */
char *fileName;
char projectDir[MAX_PATHNAME_LEN];
char fullPath[MAX_PATHNAME_LEN];
fileName = "myfile";
if (GetProjectDir (projectDir) < 0)

FmtOut ("Project is untitled\n");

else

MakePathname (projectDir, fileName, fullPath);// where fullPath has the following format: c:\myproject\myfile.dat

Note    MAX_PATHNAME_LEN is only reliable for ANSI single byte strings. For UTF-8 strings, call the IsUTF8PathLengthValid function to confirm that the file path is within the operating system character limit.

Parameters

Output
Name Type Description
directoryName char [] The buffer in which the project directory name is returned.

directoryName must be at least MAX_PATHNAME_LEN bytes long.

GetProjectDir does not add a terminating \ to directoryName.

Return Value

Name Type Description
result int The result of the call.

Code Description
0 Success.
-1 Current project has no pathname; the project is untitled.
-2 There is no current project.

Additional Information

Library: Utility Library

Include file: utility.h

LabWindows/CVI compatibility: LabWindows/CVI 3.0 and later

Examples

Refer to the following examples that use the GetProjectDir function:

  • fileio\arrayfile.cws

    Open example
  • userint\treesort.cws

    Open example
  • userint\custctrl\hyperlinkctrl\simple.cws

    Open example
Was this information helpful?

Previous

GetDir

Previous

GetDir