Windows paths and opendir()

Windows paths and opendir()

am 06.01.2007 22:05:02 von Beauford

Hi,

I have been banging my head for the last 4 hours trying to get this to work.
I simply want to be able to display a directory listing of a drive and
directory. i.e. d:\directoryname. Is this even possible???? Any help is
appreciated. I am using IIS 6 and PHP 4.4.

This is the error I get:

Warning: opendir(f:\downloads\): failed to open dir: Invalid argument in
c:\web\index.php on line 30

***** This is line 30 - if ( $handle = opendir ( $page ) )

This is the code:

$page = "f:\\downloads";
// $mode : "FULL"|"DIRS"|"FILES"
// $d : must not be defined

$display = searchdir($page);

$num = count($display);
$i = 0;

for($i = 0; $i <= $num; $i++) { echo $i." ".$display[$i]."
"; }



function searchdir ( $page , $maxdepth = -1 , $mode = "FILES" , $d = 0 )
{
if ( substr ( $page , strlen ( $page ) - 1 ) != '\\' ) { $page .= '\\' ;
}
$dirlist = array () ;
if ( $mode != "FILES" ) { $dirlist[] = $page ; }
if ( $handle = opendir ( $page ) )
{
while ( false !== ( $file = readdir ( $handle ) ) )
{
if ( $file != '.' && $file != '..' )
{
$file = $file ;
if ( ! is_dir ( $file ) ) { if ( $mode != "DIRS" ) {
$dirlist[] = $file ; } }
elseif ( $d >=0 && ($d < $maxdepth || $maxdepth < 0) )
{
$result = searchdir ( $file . '\\' , $maxdepth , $mode ,
$d + 1 ) ;
$dirlist = array_merge ( $dirlist , $result ) ;
}
}
}
closedir ( $handle ) ;
}
if ( $d == 0 ) { natcasesort ( $dirlist ) ; }
return ( $dirlist ) ;
}

?>

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Windows paths and opendir()

am 08.01.2007 16:07:21 von Bill Bolte

Your code worked fine for me - however, I did get this message at the
end:=20
"Notice: Undefined offset: 117 in C:\WebSites\Text Editor
Example\dir.php on line 11"

Other than that, it functioned as it looks like it should...

-----Original Message-----
From: Beauford [mailto:phpuser@netscan.ca]=20
Sent: Saturday, January 06, 2007 3:05 PM
To: php-windows@lists.php.net
Subject: [PHP-WIN] Windows paths and opendir()

Hi,

I have been banging my head for the last 4 hours trying to get this to
work.
I simply want to be able to display a directory listing of a drive and
directory. i.e. d:\directoryname. Is this even possible???? Any help is
appreciated. I am using IIS 6 and PHP 4.4.

This is the error I get:

Warning: opendir(f:\downloads\): failed to open dir: Invalid argument in
c:\web\index.php on line 30

***** This is line 30 - if ( $handle =3D opendir ( $page ) )=20

This is the code:

$page =3D "f:\\downloads";
// $mode : "FULL"|"DIRS"|"FILES"
// $d : must not be defined

$display =3D searchdir($page);

$num =3D count($display);
$i =3D 0;

for($i =3D 0; $i <=3D $num; $i++) { echo $i." ".$display[$i]."
"; }



function searchdir ( $page , $maxdepth =3D -1 , $mode =3D "FILES" , $d =
=3D 0 )
{
if ( substr ( $page , strlen ( $page ) - 1 ) !=3D '\\' ) { $page .=3D
'\\' ;
} =20
$dirlist =3D array () ;
if ( $mode !=3D "FILES" ) { $dirlist[] =3D $page ; }
if ( $handle =3D opendir ( $page ) )=20
{
while ( false !== ( $file =3D readdir ( $handle ) ) )
{
if ( $file !=3D '.' && $file !=3D '..' )
{
$file =3D $file ;
if ( ! is_dir ( $file ) ) { if ( $mode !=3D "DIRS" ) {
$dirlist[] =3D $file ; } }
elseif ( $d >=3D0 && ($d < $maxdepth || $maxdepth < 0) )
{
$result =3D searchdir ( $file . '\\' , $maxdepth ,
$mode , $d + 1 ) ;
$dirlist =3D array_merge ( $dirlist , $result ) ;
}
}
}
closedir ( $handle ) ;
}
if ( $d == 0 ) { natcasesort ( $dirlist ) ; }
return ( $dirlist ) ;
}

?>=20

--
PHP Windows Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php