Home > Backend Development > PHP Tutorial > php traverse directory_PHP tutorial

php traverse directory_PHP tutorial

WBOY
Release: 2016-07-14 10:10:58
Original
1198 people have browsed it

1. [Code] PHP directory traversal method 1
01

02

03 function myscandir($pathname){

04

05 foreach( glob($pathname) as $filename ){

06

07 if(is_dir($filename)){

08 myscandir($filename.'/*');

09 }else{

10 echo $filename.'
';

11 }

12 }

13 }

14 

15 myscandir('D:/wamp/www/exe1/*');

16

17 ?>

2. [Code] PHP directory traversal method 2
01

02

03 function myscandir($path){

04

05 $mydir=dir($path);

06

07 while($file=$mydir->read()){

08 $p=$path.'/'.$file;

09 

10 if(($file!=".") AND ($file!="..")){

11 echo $p.'
';

12 }

13 

14 if((is_dir($p)) AND ($file!=".") AND ($file!="..")){

15 myscandir($p);

16 }

17 }  

18 }

19

20 myscandir(dirname(dirname(__FILE__)));

21 

22 ?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477435.htmlTechArticle1. [Code]php directory traversal method 1 01 ?php 02 03 function myscandir($pathname){ 04 05 foreach( glob($pathname) as $filename ){ 06 07 if(is_dir($filename)){ 08 myscandir($filename./...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template