Directory List Script Help

Post your questions and problem reports here

Moderator: kfury77

Forum rules
Please try to follow these guidelines. This will help to receive faster and more accurate response.
  • Check the Support section of the corresponding product first. Chances are you will find your answer there;
  • Do not create new topics for already reported problems. Add your comments to the existing topics instead;
  • Create separate topic for each problem request. Do NOT post a number of non-related problem reports in a single topic;
  • Give your topic a meaningful title. Titles such as "A question," "Bug report" and "Help!" provide others no clue what your message is about;
  • Include the version number of the software you are using;
  • This is not an official customer support helpdesk. If you need a prompt and official response, please contact our support team directly instead. It may take a while until you receive a reply in the forum;
Post Reply
mike760534211
Posts: 1
Joined: Fri Jan 05, 2007 6:13 am

Directory List Script Help

Post by mike760534211 »

I wrote a script to list the files in a directory, but i got stuck when i wanted to make the script not list *.jpg and *.php files types. below is my working script to list all the files that the *.php files is located in.

<?php

function direcho($path) {
global $filetotal, $fullsize, $totaldirs;
if ($dir = opendir($path)) {
while (false !== ($file = readdir($dir))) {
if (is_dir($path."/".$file)) { // if it's a dir, check it's contents too
if ($file != '.' && $file != '..') { // but dont go recursive on '.' and '..'
echo '<li><img src="folder.jpg"><a href =\ $file )><b>' . $file . '</b></a></li><ul>';
direcho($path."/".$file );
echo '</ul>';
$totaldirs++;
}
}
else { //if it's not a dir, just output.
$tab = "      ";
$filesize = $tab . '(' . filesize ($path.'/'.$file ) . ' bytes)';
echo '<li><A HREF=' . $file . '>' . $file . '</A></li>';
$fullsize = $fullsize + filesize ($path.'/'.$file);
$filetotal++;
}
}
closedir($dir);
}
}

direcho('.');

$fullsize = round($fullsize / 1024 / 1024, 2);

echo "<font size=\"2\" face=\"Arial, Helvetica, sans-serif\">
<b>Total files</b> - $filetotal files<br>
<b>Total dirs</b> - $totaldirs directories<br>
<b>Total size</b> - $fullsize MB<br>";
?>

It lists the files in the directory just fine but being new to programming i cant seem to figure out how to make it so that it wont list *.jpg and *.php.

help would be greatly appreciated
User avatar
chrisjlocke
Top Contributor
Posts: 995
Joined: Mon Aug 01, 2005 4:12 pm
Location: Essex, UK
Contact:

Post by chrisjlocke »

Simply use an IF statement.
Post Reply