Jump to content

DosSetCurrentDir: Difference between revisions

From EDM2
Ak120 (talk | contribs)
mNo edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
==Description==
Defines the current directory.
Defines the current directory.


==Syntax==
==Syntax==
<PRE>
DosSetCurrentDir(pszDir)
#define INCL_DOSFILEMGR
#include <os2.h>


PSZ      pszDir;  /*  Address of the directory path name. */
APIRET    ulrc;    /*  Return Code. */
ulrc = DosSetCurrentDir(pszDir);
</PRE>
==Parameters==
==Parameters==
; pszDir (PSZ) - input : Address of the directory path name.
;pszDir (PSZ) - input: Address of the directory path name.
:The name is an ASCIIZ string.


The name is an ASCIIZ string.
==Return Code==
==Return Code==
ulrc (APIRET) - returns
;ulrc (APIRET) - returns:DosSetCurrentDir returns one of the following values:
 
*0 NO_ERROR
DosSetCurrentDir returns one of the following values:
*2 ERROR_FILE_NOT_FOUND  
 
*3 ERROR_PATH_NOT_FOUND  
* 0   NO_ERROR  
*5 ERROR_ACCESS_DENIED  
* 2       ERROR_FILE_NOT_FOUND  
*8 ERROR_NOT_ENOUGH_MEMORY  
* 3       ERROR_PATH_NOT_FOUND  
*26 ERROR_NOT_DOS_DISK  
* 5       ERROR_ACCESS_DENIED  
*87 ERROR_INVALID_PARAMETER  
* 8       ERROR_NOT_ENOUGH_MEMORY  
*108 ERROR_DRIVE_LOCKED  
* 26       ERROR_NOT_DOS_DISK  
*206 ERROR_FILENAME_EXCED_RANGE
* 87       ERROR_INVALID_PARAMETER  
* 108       ERROR_DRIVE_LOCKED  
* 206       ERROR_FILENAME_EXCED_RANGE


==Remarks==
==Remarks==
Line 39: Line 27:
Programs running without the NEWFILES bit can set the current directory to a non-8.3 file-name format.
Programs running without the NEWFILES bit can set the current directory to a non-8.3 file-name format.


An application must issue DosQuerySysInfo to determine the maximum path length that the operating system supports. The returned value should be used to dynamically allocate buffers that are to be used to store paths.  
An application must issue DosQuerySysInfo to determine the maximum path length that the operating system supports. The returned value should be used to dynamically allocate buffers that are to be used to store paths.


==Example Code==
==Example Code==
Line 93: Line 81:
   return NO_ERROR;
   return NO_ERROR;
}
}
</PRE>


</PRE>
==Related Functions==
==Related Functions==
* [[OS2 API:CPI:DosQueryCurrentDir|DosQueryCurrentDir]]
* [[DosQueryCurrentDir]]
* [[OS2 API:CPI:DosQueryCurrentDisk|DosQueryCurrentDisk]]
* [[DosQueryCurrentDisk]]
* [[OS2 API:CPI:DosQuerySysInfo|DosQuerySysInfo]]
* [[DosQuerySysInfo]]
* [[OS2 API:CPI:DosSetDefaultDisk|DosSetDefaultDisk]]
* [[DosSetDefaultDisk]]
 


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

Latest revision as of 11:43, 26 June 2021

Defines the current directory.

Syntax

DosSetCurrentDir(pszDir)

Parameters

pszDir (PSZ) - input
Address of the directory path name.
The name is an ASCIIZ string.

Return Code

ulrc (APIRET) - returns
DosSetCurrentDir returns one of the following values:
  • 0 NO_ERROR
  • 2 ERROR_FILE_NOT_FOUND
  • 3 ERROR_PATH_NOT_FOUND
  • 5 ERROR_ACCESS_DENIED
  • 8 ERROR_NOT_ENOUGH_MEMORY
  • 26 ERROR_NOT_DOS_DISK
  • 87 ERROR_INVALID_PARAMETER
  • 108 ERROR_DRIVE_LOCKED
  • 206 ERROR_FILENAME_EXCED_RANGE

Remarks

The directory path does not change if any member of the path does not exist. The current directory changes only for the requesting process.

For file-system drivers, the case of the current directory is set by pszDir, and not by the case of the directories on the disk. For example, if the directory "c:\bin" is created, and a pszDir value of "c:\bin," is specified, the current directory returned by DosQueryCurrentDir will be "c:\bin."

Programs running without the NEWFILES bit can set the current directory to a non-8.3 file-name format.

An application must issue DosQuerySysInfo to determine the maximum path length that the operating system supports. The returned value should be used to dynamically allocate buffers that are to be used to store paths.

Example Code

This example creates a new directory called "TEMPPROG" in the root directory, access it, and finally removes it. Some return code checking is 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