Home  >  Article  >  Backend Development  >  PHP directory processing functions opendir, readdir_PHP tutorial

PHP directory processing functions opendir, readdir_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:00:471044browse

opendir(target directory name) function to open the directory.readdir(opened target directory name) function to read the directory.closedir(opened target directory name) function to close the directory.rewinddir(opened target directory name) will The function .glob that redirects the directory pointer to the beginning of the directory (see the PHP manual for detailed parameters) The function that retrieves the directory .mkdir (1. The name of the directory to be created 2. The optional access permission length) The function that creates the directory .rmdir (the target directory function, But only empty directories can be deleted) Function to delete directories. ​

Chapter 9 (6) Directory Operations for File Processing (1)
opendir (target directory name) function to open the directory.
readdir (opened target directory name) function to read the directory.
closedir (opened target directory name) function to close the directory.
rewinddir (the name of the opened target directory) is a function that redirects the directory pointer to the beginning of the directory.
glob (see php manual for detailed parameters) function to retrieve directories.
mkdir (1. Name of the directory to be created 2. Optional access permission length) Function to create a directory.
rmdir (target directory function, but can only delete blank directories) Function to delete directories.
Example application to delete a file directory function:
function scmulu($mlming)
{
$dkml = opendir($mlming);
readdir($dkml);
readdir($dkml);
while(($wj = readdir($dkml))!==false)
{
$wj = $mlming.DIRECTORY_SEPARATOR.$wj;
if(is_dir($wj))
{
scmulu($wj);
}else
{
if(unlink($wj))
{
echo "File$wj was deleted successfully
";
}else
{
echo "File$wjfailed to delete
";
}
}
}
closedir($dkml);
if(rmdir($mlming))
{
echo "Directory$mlming was deleted successfully
";
}else
{
echo "Directory$mlmingfailed to delete
";
}
}
Example application to copy directory function:
function fzmulu($yml,$xml)
{
if(is_file($xml))
{
die("Unable to create directory $xml");
}
if(!file_exists($xml))
{
mkdir($xml);
}
$dkyml = opendir($yml);
readdir($dkyml);
readdir($dkyml);
while(($dyml = readdir($dkyml))!==false)
{
$ywj = $yml.DIRECTORY_SEPARATOR.$dyml;
$xwj = $xml.DIRECTORY_SEPARATOR.$dyml;
if(is_dir($ywj))
{
fzmulu($yml,$xml);
}else
{
copy($yml,$xml);
}
}
closedir($dkyml);
}


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445497.htmlTechArticleopendir (target directory name) function to open the directory.readdir (opened target directory name) to read the directory Function .closedir (name of the opened target directory) Function to close the directory.rewind...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn