directory search using UNC PATH

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
kingconnections
Forum Contributor
Posts: 137
Joined: Thu Jul 14, 2005 4:28 pm

directory search using UNC PATH

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Have you concatenated the UNC path to the data returned from readdir()?
kingconnections
Forum Contributor
Posts: 137
Joined: Thu Jul 14, 2005 4:28 pm

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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?
kingconnections
Forum Contributor
Posts: 137
Joined: Thu Jul 14, 2005 4:28 pm

Post 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)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply