Jump to content

DosQueryCurrentDir: Difference between revisions

From EDM2
Ak120 (talk | contribs)
Ak120 (talk | contribs)
mNo edit summary
 
Line 1: Line 1:
==Description==
Gets the full path of the current directory for the requesting process on the specified drive.
Gets the full path of the current directory for the requesting process on the specified drive.


==Syntax==
==Syntax==
<PRE>
DosQueryCurrentDir(disknum, pBuf, pcbBuf)
#define INCL_DOSFILEMGR
#include <os2.h>
 
ULONG    disknum;  /*  The drive number. */
PBYTE    pBuf;    /*  Address of the full path of the current directory. */
PULONG    pcbBuf;  /*  Address of the length, in bytes, of the pBuf buffer. */
APIRET    ulrc;    /*  Return Code. */


ulrc = DosQueryCurrentDir(disknum, pBuf, pcbBuf);
</PRE>
==Parameters==
==Parameters==
; disknum (ULONG) - input : The drive number.
;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.
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.
; pBuf (PBYTE) - output : Address of the full path of the current directory.  
: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.
; 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==
==Return Code==
ulrc (APIRET) - returns
;ulrc (APIRET) - returns:DosQueryCurrentDir returns one of the following values:
 
* 0 NO_ERROR
DosQueryCurrentDir returns one of the following values:
* 15 ERROR_INVALID_DRIVE
 
* 26 ERROR_NOT_DOS_DISK
* 0   NO_ERROR  
*108 ERROR_DRIVE_LOCKED
* 15       ERROR_INVALID_DRIVE  
*111 ERROR_BUFFER_OVERFLOW
* 26       ERROR_NOT_DOS_DISK  
* 108       ERROR_DRIVE_LOCKED  
* 111       ERROR_BUFFER_OVERFLOW


==Remarks==
==Remarks==
Line 103: Line 82:
   return NO_ERROR;
   return NO_ERROR;
}
}
</PRE>


</PRE>
==Related Functions==
==Related Functions==
*[[DosQueryCurrentDisk]]
*[[DosQueryCurrentDisk]]

Latest revision as of 04:00, 1 December 2019

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.

#define INCL_DOSFILEMGR   /* File Manager values */
#define INCL_DOSERRORS    /* DOS Error values    */
#include <os2.h>
#include <stdio.h>
#include <string.h>

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