- Impact
- 328
A simple function to list a given directory's files. Got bored 
PHP:
<?php
function list_dir($dir, $ignore = array())
{
$handle = opendir($dir);
if($handle)
{
while(false !== ($file = readdir($handle)))
{
if($file != '.' && $file != '..' && !in_array($file, $ignore))
{
$files[] = $file;
}
}
sort($files);
$list = '';
foreach($files as $file)
{
$list .= $file.'<br>';
}
}
closedir($handle);
return rtrim($list, '<br>');
}
/*
Takes two arguments $dir & $ignore
$dir = the directory you want to list
$ignore = an array of specific files you don't want listed
Example usage:
*/
echo list_dir("some/directory/", array("includes", "someotherfile.php"));
/*
Outputs something like:
about.php
contact.php
index.php
style.css
... you get the idea ;)
*/
?>








