#! /usr/bin/php MAX_DEPTH || ! is_readable($dir)) return; $dir_handle = opendir($dir) or die("Unable to open $dir\n"); while (false !== ($node = readdir($dir_handle))) { if ($node === '.' || $node === '..') continue; echo "$dir/$node\n"; if (is_dir("$dir/$node")) { dir_walk("$dir/$node", $current_depth + 1); } } } // Test the function // ------------------------------------------------------------------------------------- $dir = '.'; dir_walk($dir, 0); exit; ?>