| xHarbour Reference Documentation > Function Reference |
![]() |
![]() |
![]() |
Creates a new directory.
MakeDir( <cDirectory> ) --> nOSError
The function returns a numeric value representing the operating system error code (DOS error). A value of 0 indicates a successful operation.
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.
| See also: | DirChange(), DirRemove(), DiskChange(), DiskName(), FError(), IsDisk() |
| Category: | Directory functions , File functions |
| Source: | rtl\dirdrive.c |
| LIB: | xhb.lib |
| DLL: | xhbdll.dll |
// 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
http://www.xHarbour.com