PHP 8.3.0 RC 6 available for testing

closedir

(PHP 4, PHP 5, PHP 7, PHP 8)

closedir关闭目录句柄

说明

closedir(?resource $dir_handle = null): void

关闭由 dir_handle 指定的目录流。流必须之前被 opendir() 所打开。

参数

dir_handle

目录句柄的 resource,之前由 opendir() 所打开的。如果目录句柄没有指定,那么会假定为是 opendir() 所打开的最后一个句柄。

返回值

没有返回值。

示例

示例 #1 closedir() 例子

<?php
$dir
= "/etc/php5/";

// 打开已知目录,读取目录到变量并然后关闭
if (is_dir($dir)) {
if (
$dh = opendir($dir)) {
$directory = readdir($dh);
closedir($dh);
}
}
?>

add a note

User Contributed Notes 1 note

up
-31
foo at bar dot com
22 years ago
About deleting a directory after doing a readdir/closedir on it... I'm not sure if this is the solution, but you could try to chdir("/"); before the rmdir to make absolutely sure you aren't standing in the directory (i.e trying to pull out the rug from under yourself).
To Top