MENU
Directory
is_dir($s) returns true if $s is a directory. getcwd() returns the current working directory as a string. chdir($s) changes the current directory to $s and returns true on success. scandir($s[,$i= SCANDIR_SORT_ASCENDING]) returns an array of files and directories from the directory $s, or false on failure. $i can be SCANDIR_SORT_ASCENDING, SCANDIR_SORT_DESCEDING, or SCANDIR_SORT_ NONE. mkdir($s[,$i=0777[,$b=false]]) creates the directory $s with an access code (see chmod()) of $i, and returns true on success. If $b is set to true, then nested directories can be created. rename($s1,$s2) renames a file or directory $s1 to $s2, moving it between directories if necessary, and returns true on success. If $s2 exists, it will be overwritten. rmdir($s) removes an empty directory $s, and returns true on success.<!DOCTYPE html><html><head></head>
<body><?php
mkdir("testing");
rename ("testing","testing2");
var_dump(is_dir("testing2"));echo "<br />";
print_r(scandir("./testing2/..")); // back to the current dir
chdir("testing2");
echo getcwd();
rename("../a.html","b.html");
rmdir("../testing2");
?></body></html>
bool(true) Array ( [0] => . [1] => .. [2] => a.html [3] => action.php [4] => alpha_beta.php [5] => apache_pb.gif [6] => apache_pb.png [7] => apache_pb2.gif [8] => apache_pb2.png [9] => apache_pb2_ani.gif [10] => bar.php [11] => error.txt [12] => favicon.ico [13] => foo.php [14] => forbidden [15] => index.html [16] => intro.php [17] => restricted [18] => submit.gif [19] => test.php [20] => testing2 [21] => upload [22] => upload.php [23] => upload_file.php [24] => xampp ) E:\Program Files\xampp\htdocs\testing2 Warning: rmdir(../testing2): Directory not empty in E:\Program Files\xampp\htdocs\intro.php on line 11
Synopsis for the class Directory:
Properties |
string $path |
resource $handle |
Methods |
void close([resource $dir_handle]) ALIAS closedir(……) This closes the directory handle. |
string read([resource $dir_handle]) ALIAS readdir(……) This returns the next entry. False is returned on failure. |
void rewind([resource $dir_handle]) ALIAS rewinddir(……) This rewinds the stream to the beginning. |
RESETRUNFULL
<!DOCTYPE html><html><head></head>
<body><?php
$r=opendir(".");
while (false !== ($entry = readdir($r)))
echo "$entry"."<br />";
closedir($r);
$d=dir(".");
echo $d->path."<br />";
echo $d->read()."<br />";
echo $d->read()."<br />";
echo $d->read()."<br />";
$d->rewind();
echo $d->read()."<br />";
$d->close();
?></body></html>
<!DOCTYPE html><html><head></head>
<body><?php
echo basename("/abc/def/ghi","i")."<br />";
echo dirname("xampp/external")."<br />";
print_r(pathinfo("xampp/external/cds.php"));echo "<br />";
echo realpath(".")."<br />";
echo realpath_cache_sizE()."<br />";
echo disk_free_space(".")."<br />";
echo disk_total_space(".")."<br />";
?></body></html>
gh xampp Array ( [dirname] => xampp/external [basename] => cds.php [extension] => php [filename] => cds ) E:\Program Files\xampp\htdocs 748 1088978944 58558771200