dos12.hlp (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
DosChDir (1.2)
Function Group  Overview                          Up Next Previous
────────────────────────────────────────────────────────────────────────────
 
#define INCL_DOSFILEMGR
 
USHORT DosChDir(pszDirPath, ulReserved)
PSZ pszDirPath;      /* directory path */
ULONG ulReserved;    /* must be zero   */
 
The DosChDir function changes the current directory to the specified
directory. When a process changes the current directory, subsequent calls to
file-system functions, such as the DosOpen function, use the new directory
as the default directory. The default directory is used if no explicit path
is given with a filename.
 
The DosChDir function is a family API function.
 
Parameter   Description
────────────────────────────────────────────────────────────────────────────
 
pszDirPath  Points to the null-terminated string that specifies the new
            directory path. The string must be a valid MS OS/2 directory
            path and must not be longer than the maximum path length
            returned by the DosQSysInfo function. The name cannot conatin
            wildcard characters.
 
ulReserved  Specifies a reserved value; must be zero.
 
Return Value
 
The return value is zero if the function is successful. Otherwise, it is an
error value, which may be one of the following:
 
     ERROR_DRIVE_LOCKED
     ERROR_FILE_NOT_FOUND
     ERROR_NOT_DOS_DISK
     ERROR_NOT_ENOUGH_MEMORY
     ERROR_PATH_NOT_FOUND
 
Comments
 
This function applies to only the process changing the directory. It does
not affect the current directories of other processes. When the process
terminates, the previous default directory becomes the default directory
again.
 
When a process starts, it inherits its current directory from the parent
process.
 
Example
 
This example stores the current default drive and path, then calls the
DosChDir function to change the default path to the root directory:
 
PSZ pszPath;
USHORT cbPath = 0, usDisk;
ULONG ulLogicalDrives;
SEL selPath;
 
DosQCurDisk(&usDisk, &ulLogicalDrives); /* gets current drive        */
DosQCurDir(usDisk, (PBYTE) NULL, &cbPath); /* gets size of buffer    */
DosAllocSeg(cbPath, &selPath,           /* allocates memory          */
    SEG_NONSHARED);
pszPath = MAKEP(selPath, 0);            /* assigns it to far pointer */
DosQCurDir(usDisk, pszPath, &cbPath);   /* gets current directory    */
DosChDir("\\", 0L);                     /* changes to root directory */
    .
    .
    .
DosChDir(pszPath, 0L);                  /* restores directory        */
 
See Also
 
DosMkDir, DosOpen, DosQCurDir, DosQCurDisk, DosRmDir, DosQSysInfo,
DosSelectDisk