Write a function, PHP traverse a folder and all the files and functions D subfolders: \ phpstudy \ WWW \ test

// write a function, PHP traversing a folder all function D files and subfolders: \ phpstudy \ the WWW \ the Test
function my_dir ($ dir) {
    $ Files = Array ();
    IF ($ handle = opendir ($ dir )) {
        // Note that to add an @, otherwise there will be warning error: php5.5 + @ nor found without error)
        ! the while (($ File = readdir ($ handle)) == false) {

            if($file != ".." && $file != ".") {
                //排除根目录;
                if(is_dir($dir."/".$file)) {

                    // If a subfolder, proceeds recursively
                    $ Files [$ File] = my_dir ($ the dir "/" $ File..);
                } The else {

                    // Otherwise, it will be the name of the file into an array
                    $ Files [] = $ File;
                }
            }
        }
        closedir ($ handle);
        return $ Files;
    }
}
echo "<pre>";
"." // print_r (my_dir ( ));
print_r (my_dir ( "D: / phpstudy / the WWW / Test"));
echo "</ pre>";
Die;

Guess you like

Origin blog.csdn.net/liuzhidan123__/article/details/90238538