Link to home
Start Free TrialLog in
Avatar of Insoftservice inso
Insoftservice insoFlag for India

asked on

php opendir not working

I want to scan for all folders and files within folder c:/data
But i am getting below error.
Warning: opendir(c:/data,c:/data): The system cannot find the file specified. (code: 2)
	function listFolderFiless($dir){
    $ffs = scandir($dir);
    $i = 0;
    $list = array();
    foreach ( $ffs as $ff ){
        if ( $ff != '.' && $ff != '..' ){
            if ( strlen($ff)>=5 ) {
                if ( substr($ff, -4) == '.php' ) {
                    $list[] = $ff;
                    //echo dirname($ff) . $ff . "<br/>";
                    echo $dir.'/'.$ff.'<br/>';
                }    
            }       
            if( is_dir($dir.'/'.$ff) ) 
                    $this->listFolderFiless($dir.'/'.$ff);
        }
    }
    return $list;
}

Open in new window

But  result is same
Avatar of Ahmed Merghani
Ahmed Merghani
Flag of Sudan image

I think your path should be c:\data
Avatar of Insoftservice inso

ASKER

Tried even that
str_replace("/","\\","c:/data");
even tried giving hard code value.

This code worked on my local server but not on windows 2003 server

function ListIn($dir, $prefix = '') {
            
              $dir = rtrim($dir, '\\/');
              $result = array();

                  $h = opendir($dir);
                  
                  while (($f = readdir($h)) !== false) {
                    if ($f !== '.' and $f !== '..') {
                        if (is_dir("$dir/$f")) {
                          $result = array_merge($result, $this->ListIn("$dir/$f", "$prefix$f/"));
                        } else {
                          $result[] = $prefix.$f;
                        }
                    }
                  }
                  closedir($h);

              return $result;
            }
This works fine for me.
$handle = opendir('C:\\Food')

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ahmed Merghani
Ahmed Merghani
Flag of Sudan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
windows 2003 server . php5.4
Client had given permission to the folder on the server.
Its  resolved thx