php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #19658 is_dir or is_file doesn't work in all cases
Submitted: 2002-09-29 08:22 UTC Modified: 2002-09-30 04:21 UTC
From: dirks dot plaza at hccnet dot nl Assigned:
Status: Not a bug Package: Directory function related
PHP Version: 4.2.0 OS: Windows 2000
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: dirks dot plaza at hccnet dot nl
New email:
PHP Version: OS:

 

 [2002-09-29 08:22 UTC] dirks dot plaza at hccnet dot nl
This script works OK:
if ($handle = @opendir('.')) {
   while (false !== ($file = readdir($handle))) {  
           if (is_dir($file)) { 
		   echo "Is directory $file <BR>"; 
		   }
		   else Print "Is file $file <BR>";
   }
   closedir($handle); 
}
When I replace "." with i.e. "C:\webpages\test" (this is the directory where I run the script from) it also works fine.
But when I try the read a directory which is not in the same directory as the script i.e. "C:\webpages" than it displays that there are only files. So reading a directory lower or higher that the direcory where you are running a script from gives a wrong output.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-09-29 14:36 UTC] sniper@php.net
Thank you for taking the time to report a problem with PHP.
Unfortunately you are not using a current version of PHP -- 
the problem might already be fixed. Please download a new
PHP version from http://www.php.net/downloads.php

If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.
 [2002-09-30 04:21 UTC] hholzgra@php.net
Sorry, but the bug system is not the appropriate forum for asking
support questions. Your problem does not imply a bug in PHP itself.
For a list of more appropriate places to ask for help using PHP,
please visit http://www.php.net/support.php

Thank you for your interest in PHP.

teh filename returned by readdir() is 
always relative to the opened directory
you have to concatenate dir- and filename
to get the complete path

like 
 
  $dir = 'C:\Webpages\';
  if ($handle = @opendir($dir)) {
   while (false !== ($file = readdir($handle))) {  
           if (is_dir($dir.$file)) { 

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 11:01:30 2024 UTC