Display Directory Subfolders

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
ibanez270dx
Forum Commoner
Posts: 74
Joined: Thu Jul 27, 2006 12:06 pm
Location: Everywhere, California

Display Directory Subfolders

Post by ibanez270dx »

Hi,
I need to make a script to display the subfolders of a network directory (for example, \\network\users$\ ) ... I don't think I'm using the dir function correctly, and I don't exactly understand how it works from php.net... can someone help me out?

Thanks,
- Jeff
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Use chdir() & glob() with the GLOB_ONLYDIR parameter.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
ibanez270dx
Forum Commoner
Posts: 74
Joined: Thu Jul 27, 2006 12:06 pm
Location: Everywhere, California

Post by ibanez270dx »

How do I use them? Here is my code currently... it won't even show anything - just a blank page...

Code: Select all

foreach (glob_onlydir("\\network\users$") as $dirname) 
	{
   	 $display_names .= "$dirname";
	}
I haven't used the foreach or glob functions before, and PHP.net doesn't exactly make sense to me... sorry I'm not a pro at this...
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

There isn't such function "glob_onlydir" :P

pickle meant to this:

Code: Select all

glob('*', GLOB_ONLYDIR)
ibanez270dx
Forum Commoner
Posts: 74
Joined: Thu Jul 27, 2006 12:06 pm
Location: Everywhere, California

Post by ibanez270dx »

cool - now I don't have just a blank page... using the following code, I only get the output "array". I haven't worked with arrays either... :oops:

Code: Select all

$directories = glob('\\network\users$\*', GLOB_ONLYDIR)
I need it to basically read all the names of the directories within \\network\users$\ and display them... Please help me!
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

This topic has been discussed before, use the search :wink:
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
ibanez270dx
Forum Commoner
Posts: 74
Joined: Thu Jul 27, 2006 12:06 pm
Location: Everywhere, California

Post by ibanez270dx »

Hi,
Ok, so I got it to display the folder names... but I couldn't get it to display it from the network... (I did the testing in the current directory). However, I need it to go to \\network\users$\ . That is the path it displays from windows explorer, but it won't work in the PHP. Is there anything I'm missing? Here is my code again:

Code: Select all

<?php

$Array = glob('\\network\users$\*', GLOB_ONLYDIR); 
	
foreach($Array as $dirname)
	{
   	 $display_names .= "<a href=viewlog.php?name=$dirname>$dirname</a><br>";
	}

?>
Post Reply