包含文件信息的目录列表 [英] Directory listing with file info

查看:75
本文介绍了包含文件信息的目录列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个目录列表,而不是整个

文件名,我需要它来显示文件名减去扩展名并得到

的值charname =在文件本身。


我被告知我必须将目录列表转换为数组

然后使用foreach (数组作为项目)"通过并打开每个文件

但是我尝试了几种不同的方法而且我无法让它工作。


我'已经能够使用这个脚本按顺序列出目录

但是之后我就输了。


<?

$ 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>";


}

?>


这里我希望名字后面的$ val只是没有
的文件名
扩展(目录中的所有文件都是txt文件)然后是t他将

秒$ val显示在列表中,作为行的值

charname =在txt文件中。


任何人都知道我该怎么办?


Kim Jensen

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

推荐答案

list = Array();
list = Array();


handle = opendir(''testdir /。'');

while(false!==(
handle = opendir(''testdir/.'');
while (false !== (


file = readdir(
file = readdir(


这篇关于包含文件信息的目录列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆