xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

MakeDir()

Creates a new directory.

Syntax

MakeDir( <cDirectory> ) --> nOSError

Arguments

<cDirectory>
A character expression specifying the directory to create. The directory can be specified relative to the current directory, or absolute, including a drive letter followed by a colon.

Return

The function returns a numeric value representing the operating system error code (DOS error). A value of 0 indicates a successful operation.

Description

The function attempts to create the directory specified with <cDirectory>. If this operation fails, the function returns the OS error code indicating the reason for failure. See the FError() function for a description of OS errors.

Note that <cDirectory> cannot contain subdirectories more than one level deep.

Info

See also:DirChange(), DirRemove(), DiskChange(), DiskName(), FError(), IsDisk()
Category: Directory functions , File functions
Source:rtl\dirdrive.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example demonstrates how to create nested sub-directories
// in the current directory

   PROCEDURE Main
      LOCAL i, j, aSubDir, cSubDir, nError
      LOCAL aNewDir := { ;
         "payments\salaries"  , ;
         "payments\purchases" , ;
         "customer\marketing" , ;
         "customer\orders"    , ;
         "customer\support"     }

      FOR i:=1 TO Len( aNewDir )
         cSubDir := CurDrive()+ ":\" + CurDir() + "\"
         aSubDir := HB_ATokens( aNewDir[i], "\" )

         FOR j:=1 TO Len( aSubDir )
            cSubDir += aSubDir[j] + "\"

            nError := MakeDir( cSubDir )
            IF nError == 0
               ? "Directory", cSubDir, "successfully created"
            ELSEIF nError == 5
               ? "Directory", cSubDir, "exists already"
            ELSE
               ? "Error for", cSubDir, LTrim( Str( nError ) )
            ENDIF
         NEXT j
      NEXT i

   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe