Listing files in current directory
Posted: Fri Apr 02, 2004 10:18 pm
I wrote a function to list every file in the current directory.
Here is the code:
In the directory it is in, there are two files, this one (functions.php) and index.php. When the above function is called, it lists those two files, but then lists a blank third one, so the output looks similar to this:
Can someone figure out why I am getting this third empty array entry in $dir_files. Thanks for any help!
Here is the code:
Code: Select all
<?php
function ListDirContents($align)
{
$dir_full = shell_exec("ls");
$dir_files = explode("\n", $dir_full);
for ($i=0; $i<count($dir_files); $i++) {
$count = $i+1;
?>
<div align="<?php echo $align; ?>">
<p><?php echo $count; ?>. <a href="http://studentcenter.compbrain.net/~pn/<?php echo $dir_files[$i]; ?>"><?php echo $dir_files[$i]; ?></a></p>
</div>
<?php
}
}
?>Code: Select all
1. functions.php
2. index.php
3.