Closed Thread Icon

Topic awaiting preservation: List HTML files in dir &sub-dirs' Pages that link to <a href="https://ozoneasylum.com/backlink?for=12432" title="Pages that link to Topic awaiting preservation: List HTML files in dir &amp;amp;sub-dirs&amp;#039;" rel="nofollow" >Topic awaiting preservation: List HTML files in dir &amp;sub-dirs&#039;\

 
Author Thread
Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 09-19-2002 11:57

Yup!
I got this in a discussion where GRUMBLE needed that, and Mr.maX gave this:

code:
<?
$dir_name = "/path/to/html/files/";

$dir = opendir($dir_name);
$file_list = "";

while ($file_name = readdir($dir)) {
if (preg_match("/html\$/i", $file_name)) {
$file_list .= "$dir_name$file_name<BR>";
}
}

closedir($dir);

echo "$file_list";
?>



But I need to list the subdir files too!

Any idea or reference?

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 09-19-2002 12:49

Wakkos: I'm not sure if it is possible but you could possibly have some kind of recursive functions which checks to see if something is a directory:
http://www.php.net/is_dir

and then if it is you pass this directory back into the function which opens the directories and reads the contents. Like:

code:
function read_dir ($dir_name) {
STUFF

if (is_dir($file_name)) {
read_dir ($file_name);
}

}



It strikes me as being the most efficient way of doing it anyway.

___________________
Emps

FAQs: Emperor

Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 09-19-2002 15:16

I found this:

code:
function getDirList ($dirName) { 
$d = dir($dirName);
while($entry = $d->read()) {
if ($entry != "." && $entry != "..") {
if (is_dir($dirName."/".$entry)) {
getDirList($dirName."/".$entry);
} else {
echo $dirName."/".$entry."<br> \n";
}
}
}
$d->close();
}




And works cool, but I dunno how to exclude all files but HTML :
if (preg_match("/html\$/i", $file_name)) {
$file_list .= "$dir_name$file_name<BR>";
}

I tryied the variables change and tryied to adapt it to that script over there....
Too bad I have no Idea....

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 09-19-2002 15:34

Wakkos: Ah Jim lad try this here code arrrrrrrr:

code:
if (preg_match("/html\$/i", $entry)) { 
echo "$dir_name$file_name<BR>";
}



___________________
Emps

FAQs: Emperor

Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 09-19-2002 17:21

Understood!
I just changed the cariables in the echo too!

My problem was WHERE to add that code! but I ate some pills,. and the problem is worked out....

code:
function getDirList ($dirName) { 
$d = dir($dirName);
while($entry = $d->read()) {
if ($entry != "." && $entry != "..") {
if (is_dir($dirName."/".$entry)) {
getDirList($dirName."/".$entry);

} else {
if (preg_match("/html\$/i", $entry))
{
echo "<a href=$dirName/$entry>$entry</a><BR>";
}
}
}
}
$d->close();
}
getDirList(".");


« BackwardsOnwards »

Show Forum Drop Down Menu