is_dir
Checks whether a path is a folder.
Syntax
is_dir(string $filename): boolParameters
| Parameter | Type | Description |
|---|---|---|
| $filename | string | The path to check. |
Return value
bool`true` if the path exists and is a folder.
Examples
A folder and a file:
<?php
$file = sys_get_temp_dir() . '/ref-isdir.txt';
file_put_contents($file, '');
var_dump(is_dir(sys_get_temp_dir()));
var_dump(is_dir($file));Output:
bool(true)
bool(false)Notes
The companion is_file() checks that the path is a regular file.
See also
- file_exists — Checks whether a file or folder exists.
- mkdir — Creates a folder.
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.