meowmeow Posted April 28, 2006 Share Posted April 28, 2006 hii 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!!! Quote Link to comment Share on other sites More sharing options...
craygo Posted April 28, 2006 Share Posted April 28, 2006 I have windows and the slash doesn't seem to be a factorHere 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 fineRay Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.