Page 1 of 1

Need help with directory listings and dirs

Posted: Thu May 16, 2002 8:56 am
by pHaZed
Hey,
I have written a Directory listing script, Which is in a function with the 3rd argument of the function being $showdir
eg: function displayFiles ($path, $extension, $showdir)
then its called like:
displayFiles ("/home/wwwroot/curves/wallpapers", "jpg", "0");

I wish to be able to choose whether or not to display dirs, Thats wat the 3rd argument is for($showdirs)...
If anyone can tell me how with an if/else condition i can do
if($showdir == 1)
Any ideas on the code to display or not to display dirs?

Directory listing script

Posted: Thu May 16, 2002 4:15 pm
by cwcollins
i would loop through the listing and do a

Code: Select all

if(!is_dir(їfile_or_directory_name])){echo їfile_or_directory_name];}
the is_dir() function is doc'd at :

http://www.php.net/manual/en/function.is-dir.php

Posted: Thu May 16, 2002 5:10 pm
by sam

Code: Select all

if(!is_dir(їfile_or_directory_name]) || $isdir == 1){
echo їfile_or_directory_name];
}
And improvement of the above code.

Cheers Sam

Posted: Thu May 16, 2002 5:32 pm
by hob_goblin
i think he wants to be able to turn it off and on

which would be like

if($show_dir == "1")){

statements to show the directory

} else {

statements to execute if the directory is not going to be shown

}

Posted: Fri May 17, 2002 8:31 am
by cwcollins
ok, the final answer:

function start :::

Code: Select all

function whatever($directory,$extention,$showdir){
::: loop through directoy listing, and use this to check

Code: Select all

if(!is_dir(їfile_or_directory_name]) || $showdir == 1){ 
echo їfile_or_directory_name]; 
}
::: end loop

Code: Select all

}
end function :::

if $showdir is set to 1, it will display all entries, including directories, if not, it will ignore directories (i.e. entries that return false from the is_dir()).

the way that hob_goblin indicated will work, but why have an extra if...else? If hob_goblin's way is easier for you, use the code block that i put in the first response.

that either helped, or confused the hell out of you. good luck.

-c.w.collins

Posted: Sun May 19, 2002 8:42 am
by pHaZed
Thanks everyone,
That all really helped. I know have quite an impressive archive script for my site :D