Click to Rate and Give Feedback
MSDN
MSDN Library
System Services
File Services
File Systems
 GetCurrentDirectory Function

  Switch on low bandwidth view
GetCurrentDirectory Function

Retrieves the current directory for the current process.

Syntax

C++
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.

Multi-threaded applications and shared library code should should not use the GetCurrentDirectory function. The current directory state written by the SetCurrentDirectory function is stored as a global variable in each process, therefore multi-threaded applications cannot reliably use this value without possible data corruption from other threads that may also be reading or setting this value. This limitation also applies to the SetCurrentDirectory and GetFullPathName functions.

Examples

For an example, see Changing the Current Directory.

Requirements

Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinBase.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll
Unicode and ANSI namesGetCurrentDirectoryW (Unicode) and GetCurrentDirectoryA (ANSI)

See Also

CreateDirectory
Directory Management Functions
GetSystemDirectory
GetWindowsDirectory
RemoveDirectory
SetCurrentDirectory

Send comments about this topic to Microsoft

Build date: 7/9/2009

Community Content   What is Community Content?
Add new content RSS  Annotations
creating c:\AAA\BBB directory      duduarbel ... j104   |   Edit   |   Show History

surprisingly, the following code fail to create a directory:

saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
saAttr.bInheritHandle = TRUE;
saAttr.lpSecurityDescriptor = NULL; // this will be have to change in the future
::CreateDirectory("c:\\AAA\\BBB", &saAttr));

it will succide to create c:\AAA, but not c:\AAA\BBB

Do I have to implement it by my self , or do I miss something? suggesions?

Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker