function search_in_dir($dir, &$paths) { $dir = rtrim($dir, '/\\') . DS; $dh = opendir($dir); while ($filename = readdir($dh)) { if ($filename[0] == '.') { continue; } $path = $dir . $filename; if (is_dir($path)) { search_in_dir($path, $paths); } elseif (is_file($path)) { $paths[] = $path; } } closedir($dh); }
if (empty($output_dir) || !is_dir($output_dir)) { print "invalid OUTPUT_DIR {$output_dir}.\n\n"; help(); die; } $source_dir = rtrim(realpath($source_dir), '/\\') . DS; $output_dir = rtrim(realpath($output_dir), '/\\') . DS; print <<<EOT SOURCE_DIR: {$source_dir} OUTPUT_DIR: {$output_dir} EOT; $paths = array(); search_in_dir($source_dir, $paths); date_default_timezone_set('Asia/Shanghai'); $files_hash = array(); $count = count($paths); printf("Files count: %d\n", $count); flush(); $current = 0; $percent = -1; $last_percent = -1; foreach ($paths as $path) { $percent = round($current / $count * 100); if ($percent > $last_percent) { printf("%d%%\n", $percent); flush(); $last_percent = $percent; }