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
directory search using UNC PATH
Moderator: General Moderators
-
kingconnections
- Forum Contributor
- Posts: 137
- Joined: Thu Jul 14, 2005 4:28 pm
-
kingconnections
- Forum Contributor
- Posts: 137
- Joined: Thu Jul 14, 2005 4:28 pm
hmmm -
I think so, I can go through the 1st level of sub directories like so:
This does give me what I want, but I would somehow have to loop through each one. Hope that helps?
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?
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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
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)