Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

rmdir

Removes an empty folder.

Syntax

rmdir(string $directory): bool

Parameters

ParameterTypeDescription
$directorystringThe path to the folder.

Return value

bool`true` if the folder was removed.

Examples

Creating and removing a folder:

<?php
 
$dir = sys_get_temp_dir() . '/ref-rmdir';
if (!is_dir($dir)) {
    mkdir($dir);
}
 
var_dump(rmdir($dir));
var_dump(is_dir($dir));

Output:

bool(true)
bool(false)

Notes

The function does not remove a folder that holds files: everything inside has to be deleted first.

See also

Related recipes

In the tutorial

  • Folders and paths — Working with folders in PHP — creating them, listing files, searching by a mask, parts of a path and file information.

Thanks for reading!

Donate to the site — we work hard for you.