kaisellgren
11-13-2006, 01:38 PM
Hi,
It's me again with my wonderful ideas :)
I am trying to make a script that echoes something like this:
folder
another
yes\fold
yes\fold\anotherone
yes\folderagain
justfolder
etc
heehoo\hehSo it basically displayes EVERY folder listed each by one line.
Here's a sample script I have made so far:
function scan_directory($dir)
{
$a = scandir($dir);
$b = array();
foreach ($a as $key)
{
if ($key != "." && $key != ".." && !preg_match("/\\./",$key))
$b[] = $key; // Getting all FOLDERS, not files, to single array
}
$c = array();
foreach ($b as $key)
{
$c[] = scan_directory("$dir/$key");
}
return ($c);
}
$dir = scan_directory("kcms");
print_r($dir);But obviously it's not working corretcly... :(
Here's another one I have tried:
function scan_directory($dir)
{
$a = scandir($dir);
$b = array();
foreach ($a as $key)
{
if ($key != "." && $key != ".." && !preg_match("/\\./",$key))
$b[] = $key; // Getting all FOLDERS, not files, to single array
}
$c = "";
foreach ($b as $key)
{
$c .= scan_directory("$dir/$key");
}
return ($c);
}
$dir = scan_directory("kcms");
echo($dir);But this one outputs nothing! :(
Do anyone have any ideas? I'm doing this script for my own personal use, this script would save A LOT time if I got it working.
Thanks for your time,
Kai
It's me again with my wonderful ideas :)
I am trying to make a script that echoes something like this:
folder
another
yes\fold
yes\fold\anotherone
yes\folderagain
justfolder
etc
heehoo\hehSo it basically displayes EVERY folder listed each by one line.
Here's a sample script I have made so far:
function scan_directory($dir)
{
$a = scandir($dir);
$b = array();
foreach ($a as $key)
{
if ($key != "." && $key != ".." && !preg_match("/\\./",$key))
$b[] = $key; // Getting all FOLDERS, not files, to single array
}
$c = array();
foreach ($b as $key)
{
$c[] = scan_directory("$dir/$key");
}
return ($c);
}
$dir = scan_directory("kcms");
print_r($dir);But obviously it's not working corretcly... :(
Here's another one I have tried:
function scan_directory($dir)
{
$a = scandir($dir);
$b = array();
foreach ($a as $key)
{
if ($key != "." && $key != ".." && !preg_match("/\\./",$key))
$b[] = $key; // Getting all FOLDERS, not files, to single array
}
$c = "";
foreach ($b as $key)
{
$c .= scan_directory("$dir/$key");
}
return ($c);
}
$dir = scan_directory("kcms");
echo($dir);But this one outputs nothing! :(
Do anyone have any ideas? I'm doing this script for my own personal use, this script would save A LOT time if I got it working.
Thanks for your time,
Kai