Re: is_file() can't tell the difference between file and directory in Win32...

From: Date: Mon, 04 Nov 2002 16:09:52 +0000
Subject: Re: is_file() can't tell the difference between file and directory in Win32...
References: 1 2  Groups: php.windows 
Request: Send a blank email to php-windows+get-16721@lists.php.net to get a copy of this message
I answered my own question with a little digging on the PHPBuilder page... is_file() and is_dir() will report everything as a directory unless you first chdir() to the directory. After I added the chdir() it worked. Anyone know if that's going to be changed in the future? (I love recursion!) <? function Check_For_Slash($path) { if (substr($path, (strlen($path) - 1), 1) != "/") { $path = $path . "/"; } return($path); } function Get_Directory_Listing($path) { $base_dir = "/inetpub/wwwroot"; // all paths will be relative to webserver $base_dir = Check_For_Slash($base_dir); if ($dir_handle = opendir($base_dir . $path)) { while ($file = readdir($dir_handle)) { $path = Check_For_Slash($path); chdir($base_dir . $path); if (($file != ".") && ($file != "..")) { if (is_dir($file)) { chdir($base_dir . $path . $file); print($file . "<DIR>\n"); Get_Directory_Listing($path . $file); print("</DIR>\n"); } elseif (is_file($file)) { print("<A HREF='" . $path . $file . "'>" . $file . "</A><BR>\n"); } else { print("I don't know what " . $file . " is. <BR>\n"); } } } closedir($dir_handle); } } Get_Directory_Listing("/somedir/public"); ?> j- "Miha Nedok" <mike@voyager.unix-systems.net> wrote in message news:20021101235019.I23837-100000@voyager.zrcalo.si... > > I had similar problems. Use strcmp() with .. and . . > Or use filetype() to determine if it is a file or directory or ... > > > Mike > > > On Fri, 1 Nov 2002, Jack Kelly Dobson wrote: > > > Date: Fri, 1 Nov 2002 16:39:55 -0600 > > From: Jack Kelly Dobson <jdobson@tcgcorp.net> > > To: php-windows@lists.php.net > > Subject: [PHP-WIN] is_file() can't tell the difference between file and > > directory in Win32... > > > > Hello, > > > > This is the first time I've worked with these functions so I'm sure it's in > > Indian, not the arrows. > > > > This script identifies both files and directories as directories. What am I > > doing wrong here? > > > > I'm running as a .dll under IIS. > > > > <? > > function Get_Directory_Listing($path) { > > if ($dir_handle = opendir($path)) { > > while ($file = readdir($dir_handle)) { > > if (($file != ".") && ($file != "..")) { > > if (is_file($file)) { > > print($file . " is a file.<BR>"); > > } > > else { > > print($file . " is a directory.<BR>"); > > } > > } > > } > > closedir($dir_handle); > > } > > } > > Get_Directory_Listing("/my_path"); > > ?> > > > > Thanks j-

« previous php.windows (#16721) next »