Home >Backend Development >PHP Tutorial >PHP implementation code for traversing all files and subfolders in a directory_PHP tutorial

PHP implementation code for traversing all files and subfolders in a directory_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:02:02916browse

复制代码 代码如下:

 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 ) {...
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