I have a script that gets the current directory structure and puts it into an array. I have sub directories under these directories that I need to display. I only want to print the top directory once, and then the sub directories underneath each them. I am doing a strcmp on the directory name to see if the directories match, if they do, I only want them to print once. Below is my code. Can someone please help?
<?php
$root_directory="/ra-apps/documentation/vorfa/Deliverables";
$directory_command = "find -type d | sed 's/^.\///'| grep -v 'CVS' | grep -v 'php' | egrep -v '^$' | sort -r";
$lines=array();
exec($directory_command,$lines);
$last_line = "";
$dirpath = array();
foreach($lines as $line) {
if (strcmp($last_line, $line)) {
$last_line = $line;
array_push($dirpath,$last_line);
}
$directories = split($line, "/");
rsort($dirpath);
foreach($dirpath as $path) {
?>
<script>
fSubSubSub = insFld(fSubSub, gFld("<?php echo $path; ?>", ""))
</script>
<?
foreach($dirpath as $files) {
$files = split($files, "/");
?>
<script>
insDoc(fSubSubSub, gLnk(0, "<?php echo $path;?>", "<?php echo "$path"; ?>"))
</script>
<?php
}
}
}
?>