Retrieves the path of the directory designated for temporary files.
Syntax
DWORD WINAPI GetTempPath(
__in DWORD nBufferLength,
__out LPTSTR lpBuffer
);
Parameters
- nBufferLength [in]
-
The size of the string buffer identified by lpBuffer, in TCHARs.
- lpBuffer [out]
-
A pointer to a string buffer that receives the null-terminated string specifying the temporary file path. The returned string ends with a backslash, for example, C:\TEMP\.
Return Value
If the function succeeds, the return value is the length, in TCHARs, of the string copied to lpBuffer, not including the terminating null character. If the return value is greater than nBufferLength, the return value is the length, in TCHARs, of the buffer required to hold the path.
If the function fails, the return value is zero. To get extended error information, call
GetLastError.
Remarks
The
GetTempPath function checks for the existence of environment variables in the following order and uses the first path found:
- The path specified by the TMP environment variable.
- The path specified by the TEMP environment variable.
- The path specified by the USERPROFILE environment variable.
- The Windows directory.
Note that the function does not verify that the path exists.
Symbolic link behavior—If the path points to a symbolic link, the temp path name maintains any symbolic links.
Examples
For an example, see
Creating and Using a Temporary File.
Requirements
| Minimum supported client | Windows 2000 Professional |
| Minimum supported server | Windows 2000 Server |
| Header | WinBase.h (include Windows.h) |
| Library | Kernel32.lib |
| DLL | Kernel32.dll |
| Unicode and ANSI names | GetTempPathW (Unicode) and GetTempPathA (ANSI) |
See Also
- File Management Functions
- GetTempFileName
- Symbolic Links
Send comments about this topic to Microsoft
Build date: 7/9/2009