View Single Post

  #2 (permalink)  
Old 11-16-2004
Erich Musick
 
Posts: n/a
Default Re: Directory listing with file info

Try this:

<?
$list = Array();
$handle = opendir('../');
while (false !== ($file = readdir($handle))) {

$fileparts = explode(".",$file);
if (count($fileparts) > 1) {
array_pop($fileparts);
}
$file = join(".",$fileparts);

if ($file != "." && $file != ".." && $file != "") {
$list[] = $file;
}
}
closedir($handle);
sort ($list);
reset ($list);

while (list ($key, $val) = each ($list)) {
echo "<a href=test.php?name=$val>$val</a><br />";

}

?>

Erich Musick

Kim Jensen wrote:
> I'd like to make a directory listing where instead of the entire
> filename I need it to show the filename minus the extention and get the
> value of charname= in the file itself.
>
> I've been told that I had to turn the directory listing into an array
> and then use "foreach (array as item)" to go through and open each file
> but I've tried several different approaches and I just can't get it to
> work.
>
> I've been able to make it list the directory in order using this script
> but after that I'm lost.
>
> <?
> $list = Array();
> $handle = opendir('testdir/.');
> while (false !== ($file = readdir($handle))) {
> if ($file != "." && $file != "..") {
> $list[] = ($file);
> }
> }
> closedir($handle);
> sort ($list);
> reset ($list);
>
> while (list ($key, $val) = each ($list)) {
> echo "<a href=test.php?name=$val>$val</a><br>";
>
> }
> ?>
>
> Here I'd like the $val after the name= to be just the filename without
> the extention (all files in the directory are txt files) and then the
> second $val which it shows in the list to be the value of the line
> charname= in the txt files themselves.
>
> Anybody have an idea what I should do?
>
> Kim Jensen
>

Reply With Quote