DosSetDefaultDisk

From EDM2
Revision as of 02:55, 6 January 2017 by Ak120 (Talk | contribs)

Jump to: navigation, search

DosSetDefaultDisk sets the specified drive as the default drive for the process.

Syntax

ULONG     disknum;  /*  New default-drive number. */
APIRET    ulrc;     /*  Return Code. */

ulrc = DosSetDefaultDisk(disknum);

Parameters

disknum (ULONG) - input 
New default-drive number.
The value 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. Values outside this range will cause an error. (The number of the drive to set as default drive. (A=1, B=2 etc.) )

Returns

ulrc (APIRET) - returns

DosSetDefaultDisk returns one of the following values:

  • 0 NO_ERROR
  • 15 ERROR_INVALID_DRIVE

Include Info

#define INCL_DOSFILEMGR
#include <os2.h>

Sample Code

#define INCL_DOSFILEMGR
#include <os2.h>
#include <stdio.h> /* For printf */

if(DosSetDefaultDisk(4))   /* Set default drive to D: */
{
    printf("Can not change default drive to D:\n");
}

This example creates a backup copy of the file "CONFIG.SYS" with the new name "CONFIG.CPY", in the root directory, even if the new file name already exists.

 #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   achSourceString[80]  = "config.sys";  /* String to transform */
   UCHAR   achEditString[80]    = "*.cpy";       /* Editing string */
   UCHAR   achTargetString[200] = "";            /* Destination string buffer */
   APIRET  rc                   = NO_ERROR;      /* Return code */

   rc = DosSetDefaultDisk(3);    /* Set drive to C: (1=A, 2=B, 3=C, ...)      */
   if (rc != NO_ERROR) {
      printf("DosSetDefaultDisk error: return code = %u\n", rc);
      return 1;
   }

   rc = DosSetCurrentDir ("\\");  /*  Set directory to root */
   if (rc != NO_ERROR) {
      printf("DosSetCurrentDir error: return code = %u\n", rc);
      return 1;
   }

           /* Transform "CONFIG.SYS" using "*.CPY" to "CONFIG.CPY" */

   rc = DosEditName(1, achSourceString, achEditString, achTargetString, 200);

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

           /* Copy contents of CONFIG.SYS to the backup file */

   rc = DosCopy(achSourceString,             /* Name of file to be copied    */
                achTargetString,             /* Name of the target file      */
                DCPY_EXISTING);   /* Copy even if target file already exists */

   if (rc != NO_ERROR) {
      printf("DosCopy error: return code = %u\n", rc);
      return 1;
   } else  printf ("Backup file %s created.\n", achTargetString);
   return NO_ERROR;
}

See Also