Page 1 of 1

directory search using UNC PATH

Posted: Tue Dec 19, 2006 1:19 pm
by kingconnections
So I am trying to write a script that will search a directory structure on another server on my network.

I have tried scandir() and opendir() both work with a UNC path. UNC= \\Server\share\. But the issue is that the is_dir function does not work with the UNC path because it it uses the current working directory of opendir.

So basically my I have no way of telling my script how to loop through the directories because it can't determine if it really is one or not.


Any ideas?

Thanks

Dan

Posted: Tue Dec 19, 2006 2:06 pm
by feyd
Have you concatenated the UNC path to the data returned from readdir()?

Posted: Tue Dec 19, 2006 2:18 pm
by kingconnections
hmmm -

I think so, I can go through the 1st level of sub directories like so:

Code: Select all

if ($handle = opendir($path)) {
   while (false !== ($file = readdir($handle))) {
       if ($file != "." && $file != "..") {
       		echo "Directory: $file<br>";
       		echo "----------------------<br>";
       		$root[]=$file;
       		$path2=$path.$file;
       		//echo $path2."<BR>";
       		checkdir("$path2"); // function to call second level of directories
       		echo "<br><br>";
       		      		
       		
       		}
   }
   closedir($handle);

}




function checkdir($path) {
	
if ($handle2 = opendir($path)) {
   while (false !== ($file = readdir($handle2))) {
       if ($file != "." && $file != "..") {
       	
       
       		echo "$file<br>";
       		}
   }
   closedir($handle2);

}


}

This does give me what I want, but I would somehow have to loop through each one. Hope that helps?

Posted: Tue Dec 19, 2006 2:26 pm
by feyd
That doesn't answer the question I asked. That's okay though. Have you tried the directory tree code posted in Code Snippets?

Posted: Tue Dec 19, 2006 2:45 pm
by kingconnections
Ok, so I just tried that code in the code snippets section. Very nice btw! Any how it did work, it took a long amount of time. I had to change the timeout limit for the script. But that is ok. I might be able to setup a job to run it at like midnight. Next question, how do I parse the arrays or I guess in this case arrays back out. Can I do the normal:

Code: Select all

foreach ($array as $key => $value)

Posted: Tue Dec 19, 2006 4:29 pm
by feyd
The code found in that thread as is will likely need recursive handling as it's nested. However I have posted at other times code that produces a flat tree. Both can be iterated by foreach(). The nested one will require special handling, just so you know.