DosSetDefaultDisk: Difference between revisions
Appearance
m Martini moved page OS2 API:DosSetDefaultDisk to OS2 API:CPI:DosSetDefaultDisk |
No edit summary |
||
Line 1: | Line 1: | ||
== | ==Description== | ||
Sets the specified drive as the default drive. | |||
==Syntax== | |||
<PRE> | |||
#define INCL_DOSFILEMGR | |||
#include <os2.h> | |||
ULONG disknum; /* New default-drive number. */ | |||
APIRET ulrc; /* Return Code. */ | |||
===Parameters | ulrc = DosSetDefaultDisk(disknum); | ||
</PRE> | |||
==Parameters== | |||
; ULONG | ; 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=== | ===Returns=== | ||
ulrc (APIRET) - returns | |||
DosSetDefaultDisk returns one of the following values: | |||
* 0 NO_ERROR | |||
* 15 ERROR_INVALID_DRIVE | |||
===Include Info=== | ===Include Info=== | ||
Line 40: | Line 50: | ||
} | } | ||
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 */ | |||
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> | |||
===See Also=== | ===See Also=== | ||
* [[OS2 API:DosQueryCurrentDisk|DosQueryCurrentDisk]] | |||
[[OS2 API:DosQueryCurrentDisk|DosQueryCurrentDisk]] | * [[OS2 API:DosQueryCurrentDisk|DosQueryCurrentDisk]] | ||
* [[OS2 API:DosSetCurrentDir|DosSetCurrentDir]] | |||
[[Category:The OS/2 API Project]] | [[Category:The OS/2 API Project]] |
Revision as of 19:01, 9 June 2016
Description
Sets the specified drive as the default drive.
Syntax
#define INCL_DOSFILEMGR #include <os2.h> 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>
Usage Explanation
DosSetDefaultDisk sets the specified drive as the default drive for the process.
Relevant Structures
Gotchas
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; }