Syntax
#include <direct.h> int mkdir(char *pathname);Description
mkdir creates a new directory with the specified pathname. Because only one directory can be created at a time, only the last component of pathname can name a new directory.
mkdir returns the value 0 if the directory was created. A return value of -1 indicates an error, and errno is set to one of the following values: compact break=fit.
Value
This example creates two new directories: one at the root on drive C:, and one in the tmp subdirectory of the current working directory.
#include <stdio.h>#include <direct.h>
#include <string.h>
int main(void)
{
char *dir1,*dir2;
/* Create the directory "aleng" in the root directory of the C: drive. */
dir1 = "c:\\aleng";
if (0 == (mkdir(dir1)))
printf("%s directory was created.\n", dir1);
else
printf("%s directory was not created.\n", dir1);
/* Create the subdirectory "simon" in the current directory. */
dir2 = "simon";
if (0 == (mkdir(dir2)))
printf("%s directory was created.\n", dir2);
else
printf("%s directory was not created.\n", dir2);
/* Remove the directory "aleng" from the root directory of the C: drive. */
printf("Removing directory 'aleng' from the root directory.\n");
if (rmdir(dir1))
perror(NULL);
else
printf("%s directory was removed.\n", dir1);
/* Remove the subdirectory "simon" from the current directory. */
printf("Removing subdirectory 'simon' from the current directory.\n");
if (rmdir(dir2))
perror(NULL);
else
printf("%s directory was removed.\n", dir2);
return 0;
/****************************************************************************
The output should be:
c:\aleng directory was created.
simon directory was created.
Removing directory 'aleng' from the root directory.
c:\aleng directory was removed.
Removing subdirectory 'simon' from the current directory.
simon directory was removed.
****************************************************************************/
}
Related Information