Jump to content


Photo

fileSearch - return() not working..


  • Please log in to reply
4 replies to this topic

#1 chokri

chokri
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 14 September 2006 - 03:09 PM

this is the first time i'm using php for website development.  i'm having issues with a fileSearch function i created to return a file's location.  the code is as follows:

   function fileSearch($tempFile,$curdirLoc)
   {
     $fileFound = false;
     $compfileLoc = null;
     $curDir = scandir($curdirLoc);
     foreach($curDir as $curEntry)
     {
        if($curEntry != "." && $curEntry != "..")
	{
	   $myLoc = $curdirLoc."\\".$curEntry;
           if(is_dir($myLoc))
           {
              fileSearch($tempFile,$myLoc);
           }
           else
           {
              if(strcmp($curEntry,$tempFile) == 0)
              { 
                 $compfileLoc = $myLoc;
                 $fileFound = true;
              }
           }
        }
     }
     if($fileFound) {return $compfileLoc;}
   }

i know the code works and finds the file.  the problem is when returning $compfileLoc.

if $compfileLoc = "c:\Inetpub\wwwroot\website\sitemap.php" it works
if $compfileLoc = "c:\Inetpub\wwwroot\website\Content\Contact_Us\Contact_Information.php" it doesn't work.

are there any limits to what can be returned?  i can't imagine the "\" causing problems since it works for some files.  i'd truly appreciate any help that can be provided!

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 14 September 2006 - 03:44 PM

Try chaning the code this way:

<?php

   function fileSearch($tempFile,$curdirLoc)
   {
     $fileFound = false;
     $compfileLoc = null;
     $curDir = scandir($curdirLoc);
     foreach($curDir as $curEntry)
     {
        if($curEntry != "." && $curEntry != "..")
	{
	   $myLoc = $curdirLoc."\\".$curEntry;
           if(is_dir($myLoc))
           {
              $compfileLoc=fileSearch($tempFile,$myLoc);
              if(compfileLoc!==FALSE){return $compfileLoc;}
           }
           else
           {
              if(strcmp($curEntry,$tempFile) == 0)
              { 
                 $compfileLoc = $myLoc;
                 $fileFound = true;
              }
           }
        }
     }
     if($fileFound) {return $compfileLoc;}
     else{return FALSE;}
   }

?>

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 chokri

chokri
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 14 September 2006 - 03:59 PM

YOU ROCK!  that worked.

THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU

i ate many, many smarties trying to figure out what was wrong.

#4 chokri

chokri
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 14 September 2006 - 04:06 PM

i spoke too soon.

previously:
if $compfileLoc = "c:\Inetpub\wwwroot\website\sitemap.php" it works
if $compfileLoc = "c:\Inetpub\wwwroot\website\Content\Contact_Us\Contact_Information.php" it doesn't work

after doing as you suggested orio, now it's:
if $compfileLoc = "c:\Inetpub\wwwroot\website\sitemap.php" it doesn't work
if $compfileLoc = "c:\Inetpub\wwwroot\website\Content\Contact_Us\Contact_Information.php" it works

#5 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 14 September 2006 - 05:39 PM

I think it should work fine now :)

<?php

   function fileSearch($tempFile,$curdirLoc)
   {
     $fileFound = false;
     $compfileLoc = null;
     $curDir = scandir($curdirLoc);
     foreach($curDir as $curEntry)
     {
        if($curEntry != "." && $curEntry != "..")
	{
	   $myLoc = $curdirLoc."\\".$curEntry;
           if(is_dir($myLoc))
           {
              $compfileLoc=fileSearch($tempFile,$myLoc);
              if(compfileLoc!==FALSE){return $compfileLoc;}
           }
           else
           {
              if(strcmp($curEntry,$tempFile) == 0)
              { 
                 $compfileLoc = $myLoc;
                 return $compfileLoc;
              }
           }
        }
     }
     if($fileFound) {return $compfileLoc;}
     else{return FALSE;}
   }

?>

Orio.
Think you're smarty?

(Gone until 20 to November)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users