RAD Studio |  |

_rmdir, _wrmdir

Header File

dir.h

Category

Directory Control Routines

Prototype

int _rmdir(const char *path);

int _wrmdir(const wchar_t *path);

Description

Removes a directory.

_rmdir deletes the directory whose path is given by path. The directory named by path

- must be empty
- must not be the current working directory
- must not be the root directory

Return Value

_rmdir returns 0 if the directory is successfully deleted. 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 | Path or file function not found

Example

Copy Code

    #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++
_rmdir | + | + |  |
_wrmdir |  | NT only |  |

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!