Skip to content

Instantly share code, notes, and snippets.

@rkalkani
Last active July 12, 2016 12:01
Show Gist options
  • Save rkalkani/c565e368a88c85777ce2293438c48558 to your computer and use it in GitHub Desktop.
Save rkalkani/c565e368a88c85777ce2293438c48558 to your computer and use it in GitHub Desktop.
PHP script to print all file in directory and sub-directories recursively
<?php
// Origianlly : http://php.net/manual/en/function.scandir.php#110570
function printAllFile($dir) {
$result = array();
$cdir = scandir($dir);
foreach ($cdir as $key => $value)
{
if (!in_array($value,array(".","..")))
{
if (is_dir($dir . DIRECTORY_SEPARATOR . $value))
{
$result[$value] = printAllFile($dir . DIRECTORY_SEPARATOR . $value);
}
else
{
print($dir . DIRECTORY_SEPARATOR . $value);
echo PHP_EOL;
}
}
}
return ($result);
}
printAllFile('.');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment