RAD Studio
ContentsIndex
PreviousUpNext
mkdir, _wmkdir

Header File 

dir.h  

Category 

Directory Control Routines 

Prototype 

int mkdir(const char *path); 

int _wmkdir(const wchar_t *path); 

Description 

Creates a directory. 

mkdir is available on UNIX, though it then takes an additional parameter. 

mkdir creates a new directory from the given path name path. 

Return Value 

mkdir returns the value 0 if the new directory was created. 

A return value of -1 indicates an error, and the global variable errno is set to one of the following values:

EACCES 
Permission denied 
ENOENT 
No such file or directory 

Example

#include <stdio.h>
#include <process.h>
#include <dir.h>
#define DIRNAME "testdir.$$$"
int main(void)
{
    int stat;
    stat = mkdir(DIRNAME);
    if (!stat)
           printf("Directory created\n");
    else
    {
       printf("Unable to create directory\n");
       exit(1);
    }
    getchar();
    system("dir/p");
    getchar();
    stat = rmdir(DIRNAME);
    if (!stat)
           printf("\nDirectory deleted\n");
    else
    {
           perror("\nUnable to delete directory\n");
       exit(1);
    }
    return 0;
}

Portability

 
POSIX 
Win32 
ANSI C 
ANSI C++ 
mkdir 
 
 
_wmkdir 
 
NT only 
 
 
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!