Displaying just Dirs

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eggoz
Forum Commoner
Posts: 43
Joined: Fri Dec 27, 2002 8:51 pm

Displaying just Dirs

Post by eggoz »

I wrote a script to print out all dirs and files. Now I am trying to edit it so that it only shows the Dirs. I did it on a previous code that I wrote, but this one just seems to ignore it. Also is there a way to split up the file names and dirs. So instead of showing the full path, it will only show the file name and one directory up for example?The Code Thanks for the help.
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post by PrObLeM »

Hope this helps

Code: Select all

<?php

if ($handle = opendir('foldertoloop/')) {
   while (false !== ($file = readdir($handle))) 
   {
       				print"the directory or file is: $file\n";
    }
   closedir($handle);
?>
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

[php_man]is_file[/php_man] and [php_man]pathinfo[/php_man] etc might be what you are looking for.
Last edited by McGruff on Tue Aug 09, 2005 10:04 am, edited 1 time in total.
eggoz
Forum Commoner
Posts: 43
Joined: Fri Dec 27, 2002 8:51 pm

Post by eggoz »

I think I was misunderstood. I already created a script http://pavilionhome.dyndns.org:45/test.txt or .php if you want to see it in action. When I set the dir to /tmp or some other dir on the linux box it works and only lets me see the dirs not files. But when I point it on a mounted drive it lists alllll the files. I can't figure out why.

The other part of my question is about printing the path. Instead of printing /tmp/sub1/sub2/file.ext, I need to know if you can just it to print one sub directory or /sub2/file.ext?

Thanks for the help.
eggoz
Forum Commoner
Posts: 43
Joined: Fri Dec 27, 2002 8:51 pm

Post by eggoz »

One correction. It only works when I set the directory to ./ .Nothing else works.
Post Reply