RAD Studio |  |

_getdcwd, _wgetdcwd

Header File

direct.h

Category

Directory Control Routines

Prototype

char * _getdcwd(int drive, char *buffer, int buflen);

wchar_t * _wgetdcwd(int drive, wchar_t *buffer, int buflen);

Description

Gets current directory for specified drive.

_getdcwd gets the full path name of the working directory of the specified drive (including the drive name), up to buflen bytes long, and stores it in buffer. If the full path name length (including the null-terminator) is longer than buflen, an error occurs. The drive is 0 for the default drive, 1=A, 2=B, and so on.

If the working directory is the root directory, the terminating character for the full path is a backslash. If the working directory is a subdirectory, there is no terminating backslash after the subdirectory name.

If buffer is NULL, _getdcwd allocates a buffer at least buflen bytes long. You can later free the allocated buffer by passing the _getdcwd return value to the free function.

Return Value

If successful, _getdcwd returns a pointer to the buffer containing the current directory for the specified drive.

Otherwise it returns NULL, and sets the global variable errno to one of the following values:

ENOMEM | Not enough memory to allocate a buffer (buffer is NULL)
ERANGE | Directory name longer than buflen (buffer is not NULL)

Example

Copy Code

    #include <direct.h>
    #include <stdio.h>
    char buf[65];
    void main()
    {
      if (_getdcwd(3, buf, sizeof(buf)) == NULL)
        perror("Unable to get current directory of drive C");
      else
        printf("Current directory of drive C is %s\n",buf);
    }

Portability

| POSIX | Win32 | ANSI C | ANSI C++
_getdcwd |  | + |  |
_wgetdcwd |  | NT only |  |

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!