Retrieves the current directory for the current process.
Syntax
|
DWORD WINAPI GetCurrentDirectory(
__in DWORD nBufferLength,
__out LPTSTR lpBuffer
);
|
Parameters
- nBufferLength [in]
-
The length of the buffer for the current directory string, in TCHARs. The
buffer length must include room for a terminating null character.
- lpBuffer [out]
-
A pointer to the buffer that receives the current directory string. This null-terminated string specifies the
absolute path to the current directory.
To determine the required buffer size, set this parameter to NULL and the
nBufferLength parameter to 0.
Return Value
If the function succeeds, the return value specifies the number of characters that are written to the buffer,
not including the terminating null character.
If the function fails, the return value is zero. To get extended error information, call
GetLastError.
If the buffer that is pointed to by lpBuffer is not large enough, the return value
specifies the required size of the buffer, in characters, including the null-terminating character.
Remarks
Each process has a single current directory that consists of two parts:
- A disk designator that is either a drive letter followed by a colon, or a server name followed by a share
name (\\servername\sharename)
- A directory on the disk designator
To set the current directory, use the
SetCurrentDirectory function.
In certain rare cases, if the specified directory is on the current drive, the function might omit the drive
letter and colon from the path. Therefore, the size that is returned by the function might be two characters less
than the size of the specified string, not including the terminating null character. This behavior might occur in
edge situations such as in a services application. If you need the drive letter, make a subsequent call to
GetFullPathName to retrieve the drive letter.
Examples
For an example, see
Changing the Current Directory.
Requirements
| Client | Requires Windows Vista, Windows XP, or Windows 2000 Professional. |
| Server | Requires Windows Server 2008, Windows Server 2003, or Windows 2000 Server. |
|---|
| Header | Declared in WinBase.h; include Windows.h. |
| Library | Use Kernel32.lib. |
| DLL | Requires Kernel32.dll. |
| Unicode/ANSI | Implemented as GetCurrentDirectoryW (Unicode) and GetCurrentDirectoryA (ANSI). |
See Also
CreateDirectory
Directory Management Functions
GetSystemDirectory
GetWindowsDirectory
RemoveDirectory
SetCurrentDirectory
Send comments about this topic to Microsoft
Build date: 8/28/2008