DosQueryCurrentDir

Gets the full path of the current directory for the requesting process on the specified drive.

Syntax
DosQueryCurrentDir(disknum, pBuf, pcbBuf)

Parameters

 * disknum (ULONG) - input: The drive number.
 * The value 0 means the current drive, 1 means drive A, 2 means drive B, 3 means drive C, and so on. The maximum possible value is 26, which corresponds to drive Z.


 * pBuf (PBYTE) - output: Address of the full path of the current directory.
 * pcbBuf (PULONG) - in/out : Address of the length, in bytes, of the pBuf buffer.
 * Input - This field contains the length, in bytes, of the directory path buffer.
 * Output - If an error is returned because the buffer is too small, this field contains the required length, in bytes, of the buffer.

Return Code

 * ulrc (APIRET) - returns:DosQueryCurrentDir returns one of the following values:
 * 0 NO_ERROR
 * 15 ERROR_INVALID_DRIVE
 * 26 ERROR_NOT_DOS_DISK
 * 108 ERROR_DRIVE_LOCKED
 * 111 ERROR_BUFFER_OVERFLOW

Remarks
The drive letter is not part of the returned string. The string does not begin with a backslash, and it ends with a byte containing 0x00.

The system provides the length of the returned path-name string in pcbBuf, which does not include the ending null byte. If the pBuf buffer is not large enough to hold the current-directory path string, the system returns the required length, in bytes, for the pBuf buffer in pcbBuf.

For file-system drivers, the case of the current directory is set at the time of creation.

Programs running without the NEWFILES bit set are allowed to issue DosSetCurrentDir for a directory that is not in the 8.3 file-name format.

An application must issue DosQuerySysInfo to determine the maximum path length supported by the operating system. The returned value should be used to dynamically allocate buffers that are to be used to store paths.

Example Code
This example shows how to create, use, and then delete a new directory named "TEMPPROG". Some return code checking has been omitted for brevity. 
 * 1) define INCL_DOSFILEMGR  /* File Manager values */
 * 2) define INCL_DOSERRORS   /* DOS Error values    */
 * 3) include 
 * 4) include 
 * 5) include 

int main(VOID) { UCHAR  achOrigDirName[256] = "";            /* Original directory name  */ UCHAR  achNewDirName[256]  = "\\TEMPPROG";  /* New directory to create  */ UCHAR  achDirName[256]     = "";          /* Directory name for queries */ ULONG  cbDirPathLen    = 0;               /* Length of directory path   */ PEAOP2 pEABuf       = NULL;   /* Extended Attribute buffer pointer      */ ULONG  ulDriveNum   = 0;      /* Drive number: current=0, A=1, B=2, ... */  APIRET  rc           = NO_ERROR;      /* Return code                     */

cbDirPathLen = (ULONG) sizeof(achOrigDirName); rc = DosQueryCurrentDir(ulDriveNum, achOrigDirName, &cbDirPathLen);

if (rc != NO_ERROR) { printf("DosQueryCurrentDir error: return code = %u\n", rc); return 1; } else printf ("Original dir. = \\%s\n", achOrigDirName);

pEABuf = NULL; /* Indicate no EAs are to be defined for the directory  */ rc = DosCreateDir(achNewDirName, pEABuf);  /* Create the new directory */

if (rc != NO_ERROR) { printf("DosCreateDir error: return code = %u\n", rc); return 1; }

rc = DosSetCurrentDir (achNewDirName);  /* Change to new directory     */

ulDriveNum = 0; cbDirPathLen = (ULONG) sizeof(achDirName); rc = DosQueryCurrentDir(ulDriveNum, achDirName, &cbDirPathLen);

if (rc != NO_ERROR) { printf("DosQueryCurrentDir error: return code = %u\n", rc); return 1; } else printf ("Current dir. = \\%s\n", achDirName);

strcpy(achDirName,"\\");

rc = DosSetCurrentDir (achDirName);    /* Change to root directory     */ rc = DosDeleteDir (achNewDirName);     /* Delete the new directory     */

return NO_ERROR; } 

Related Functions

 * DosQueryCurrentDisk
 * DosQuerySysInfo
 * DosSetCurrentDir
 * DosSetDefaultDisk