Jump to content

DosSetDefaultDisk: Difference between revisions

From EDM2
Ak120 (talk | contribs)
mNo edit summary
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==DosSetDefaultDisk==
DosSetDefaultDisk sets the specified drive as the default drive for the process.


===Syntax===
==Syntax==
DosSetDefaultDisk(disknum)


rc = DosSetDefaultDisk( ''ulDrive'' );
==Parameters==
 
;disknum (ULONG) - input: New default-drive number.
===Parameters===
: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.))
 
; ULONG ''ulDrive'' (input)
: The number of the drive to set as default drive. (A=1, B=2 etc.)


===Returns===
===Returns===
 
;ulrc (APIRET) - returns:DosSetDefaultDisk returns one of the following values:
*0 NO_ERROR
APIRET rc
*15 ERROR_INVALID_DRIVE
0       NO_ERROR
15     ERROR_INVALID_DRIVE


===Include Info===
===Include Info===
  #define INCL_DOSFILEMGR
  #define INCL_DOSFILEMGR
  #include <os2.h>
  #include <os2.h>
===Usage Explanation===
DosSetDefaultDisk sets the specified drive as the default drive for the process.
===Relevant Structures===
===Gotchas===


===Sample Code===
===Sample Code===
Line 40: Line 27:
  }
  }


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.
<PRE>
#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 */


===See Also===
  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;
}
</PRE>


[[OS2 API:DosQueryCurrentDisk|DosQueryCurrentDisk]]
==See Also==
* [[DosQueryCurrentDisk]]
* [[DosQueryCurrentDisk]]
* [[DosSetCurrentDir]]


[[Category:The OS/2 API Project]]
[[Category:Dos]]

Latest revision as of 11:47, 26 June 2021

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

Syntax

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