1. 程式人生 > >php遞迴遍歷資料夾

php遞迴遍歷資料夾

// 遞迴遍歷資料夾
function test($dirs) {

    $base_dir = $dirs;
    foreach (scandir($dirs) as $file) {
      if (is_file($file)) {
        echo "檔案:".$file."\n";
      } else if (is_dir($file) && $file != '.' && $file != '..') {
        echo "資料夾:".$file."\n";
        call_user_func("test",$base_dir.$file);
        //test($base_dir.$file);
      }
    }
  }
test("/var/www/test/");