Jump to content

php directories on windows


meowmeow

Recommended Posts

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:
[code]
$path = "C:\Documents and Settings\blablabla\Desktop\TEST\\";
$myDirectory = opendir($path);
while($entryName = readdir($myDirectory))
{
$dirs[]=$entryName;
}
closedir($myDirectory);
print_r($dirs);
[/code]
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...
[code]

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>";
  }
  }
}
[/code]
and here i can't get thru...

it prints: is a directory<br>
this part: [code]echo readdir($mydirectory2)."<br>"; [/code] prints a .
and this part : [code]echo "  ".$dir_name."<br>";[/code] 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!!!
Link to comment
Share on other sites

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

Here is the code I use to read a directory

[code]<?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);
}
?>[/code]

Works for me fine

Ray
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.