Heim  >  Artikel  >  Backend-Entwicklung  >  PHP遍历某个目录下的所有文件和子文件夹的实现代码_PHP教程

PHP遍历某个目录下的所有文件和子文件夹的实现代码_PHP教程

WBOY
WBOYOriginal
2016-07-21 15:02:02863Durchsuche

复制代码 代码如下:

 function read_all_dir ( $dir )
    {
        $result = array();
        $handle = opendir($dir);
        if ( $handle )
        {
            while ( ( $file = readdir ( $handle ) ) !== false )
            {
                if ( $file != '.' && $file != '..')
                {
                    $cur_path = $dir . DIRECTORY_SEPARATOR . $file;
                    if ( is_dir ( $cur_path ) )
                    {
                        $result['dir'][$cur_path] = read_all_dir ( $cur_path );
                    }
                    else
                    {
                        $result['file'][] = $cur_path;
                    }
                }
            }
            closedir($handle);
        }
        return $result;
    }
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/327951.htmlTechArticle复制代码 代码如下: ?php function read_all_dir ( $dir ) { $result = array(); $handle = opendir($dir); if ( $handle ) { while ( ( $file = readdir ( $handle ) ) !== false ) {...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn