Home  >  Article  >  Backend Development  >  PHP move directory custom function

PHP move directory custom function

高洛峰
高洛峰Original
2016-10-21 10:12:561165browse

Mobile Directory

/**
 * 移动目录
 * @param string    $dirName   要移动的目录名称
 * @return string   
 */
function removedir($dirName){
$result = false;
    if(! is_dir($dirName)){
      return $result;
    }
    $handle = opendir($dirName);
    while(($file = readdir($handle)) !== false){
        if($file != '.' && $file != '..') {
            $dir = $dirName . DIRECTORY_SEPARATOR . $file;
            is_dir($dir) ? removeDir($dir) : unlink($dir);
        }
    }
    closedir($handle);
    $result = rmdir($dirName) ? true : false;
    return $result;
}


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