Code for PHP to traverse the folder and all of its files

Source: Internet
Author: User
Tags glob
PHP implementation to traverse the current folder and all the files and folders under the code, the main use of recursion, there is a need for friends, you can refer to the study.

The code is as follows:

     Read ()) {if ($file! = '. ' && $file! = ') {$path 2 = $path. '              /'. $file; if (Is_dir ($path 2)) {echo $file. "                       \ t ";              Getdir ($path 2);              }else {echo $file. ";    }}}} Getdir ($path);    Echo ';      function Get_dir_scandir ($path) {$tree = array ();          foreach (Scandir ($path) as $single) {if ($single! = '. ' && $single! = ') {$path 2 = $path. '              /'. $single;  if (Is_dir ($path 2)) {echo $single. "                   \ r \ n ";              Get_dir_scandir ($path 2);  }else {echo $single. "              \ r \ n ";     }}}} Get_dir_scandir ($path);   Echo ';      function Get_dir_glob () {$tree = array ();  foreach (Glob ('./curl/* ') as $single) {echo $single.      \ r \ n "; }} get_dir_glob ();      Echo ';      function Myscandir ($path) {if (!is_dir ($path)) return;  foreach (Scandir ($path) as $file) {if ($file! = '. ')          && $file! = ' ... ') {$path 2= $path. '              /'. $file;                  if (Is_dir ($path 2)) {echo $file;              Myscandir ($path 2);  }else {echo $file. '              ';      }}}} Myscandir ($path);   Echo '; function Myglob ($path) {$path _pattern = $path. '      /*';                  foreach (Glob ($path _pattern) as $file) {if (Is_dir ($file)) {echo $file;              Myscandir ($file);  }else {echo $file. '              '; }}} Myglob ($path);? >
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.