Jump to content


Photo

php directories on windows


  • Please log in to reply
1 reply to this topic

#1 meowmeow

meowmeow
  • Members
  • Pip
  • Newbie
  • 2 posts
  • LocationItaly

Posted 28 April 2006 - 04:32 PM

hi
i consider myself quite experienced at php... but am having a nervous breakdown on something real stupid.

I installed an emulator on a windows computer, and am trying to use php scripts on the pc.

so i do this:
$path = "C:\Documents and Settings\blablabla\Desktop\TEST\\";
$myDirectory = opendir($path);
while($entryName = readdir($myDirectory))
{
 $dirs[]=$entryName;
}
closedir($myDirectory);
print_r($dirs);
so far so good. I get a list of the directories within $path.
Array
(
[0] => .
[1] => ..
[2] => 640x800
[3] => 800x600
[4] => 800x800
[5] => BuffMonster
[6] => deleteemptydirs.bat
[7] => formato_immagini.bat
)
then...

foreach($dirs as $value){
 
 if($value!="." && $value!="..")
 {
  echo $path.$value."\\<br>";
  if(is_dir($path.$value)){
   echo "is a directory<br>";
   $mydirectory2=opendir($path.$value."\\");
   echo readdir($mydirectory2)."<br>";;
   while(($dir_name = readdir($mydirectory2)) !== FALSE);
   {
    echo "  ".$dir_name."<br>";
   }
   closedir($mydirectory2);
   print "<hr>";
  }
  }
}
and here i can't get thru...

it prints: is a directory<br>
this part:
echo readdir($mydirectory2)."<br>";
prints a .
and this part :
echo "  ".$dir_name."<br>";
just prints

It wont tell me whats inside dir... I'm guessing the problem is that windows uses \ instead of /
so i have to use "\\" each time and i can get confusing... but this should be so simple can't figure out why it doesn't work...
please help!!!

#2 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 28 April 2006 - 06:18 PM

I have windows and the slash doesn't seem to be a factor

Here is the code I use to read a directory

<?php
$dir = "c:/Inetpub/wwwroot/phpforum/pdffiles";
if ($handle = opendir($dir)) {
   while (false !== ($file = readdir($handle))) {
        // This gets rid of the . and ..
        if (ereg("[a-z]", $file)){
                  print '<a href="path/to/files/'.$file.'">'.$file.'<a><br />';
               }
              }
   closedir($handle);
}
?>

Works for me fine

Ray




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users