From EDM2
Jump to: navigation, search

Creates a new directory.


DosCreateDir(pszDirName, peaop2)


pszDirName (PSZ) - input 
Address of the ASCIIZ directory path name, which may contain a drive specification.
If no drive is specified, the current drive is assumed.
DosQuerySysInfo is called by an application during initialization to determine the maximum path length allowed by the operating system.
peaop2 (PEAOP2) - in/out 
Address of the extended attribute buffer, which contains an EAOP2 data structure.
On input, the fpGEA2List field and oError fields are ignored. The EA setting operation is performed on the information contained in fpFEA2List. If extended attributes are not to be defined or modified, then peaop2 must be set to null.
On output, fpGEA2List and fpFEA2List are unchanged. The area that fpFEA2List points to is unchanged. If an error occurred during the set, oError is the offset of the FEA2 where the error occurred. The return code is the error code corresponding to the condition generating the error. If no error occurred, oError is undefined.
If peaop2 is zero, then no extended attributes are defined for the directory.

Return Code

ulrc (APIRET) - returns
DosCreateDir returns one of the following values:
  • 0 NO_ERROR


DosCreateDir enables an application to define extended attributes for a subdirectory at the time of its creation.

If any subdirectory names specified in the path name do not exist, the subdirectory is not created. Upon successful return, a subdirectory is created at the end of the specified path.

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.

If a program with its NEWFILES bit set tries to create a directory on an FAT file system drive and specifies blanks immediately preceding the dot in a file name, the system rejects the name. For example, if c: is an FAT file system drive, the name "file .txt" is rejected, but "file.txt" is accepted.

Example Code

This example creates the new directory "TEMPPROG" in the root directory, access it, and then deletes it. Some return codes are not checked 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);


   rc = DosSetCurrentDir (achDirName);     /* Change to root directory     */
   rc = DosDeleteDir (achNewDirName);      /* Delete the new directory     */

   return NO_ERROR;

Related Functions