0

hi..please help me to have code that will display list of folders
from a given directory in php or javascript.

for example i want to display in a page the list of folders
in my c:\Program Files.

Thanks in advance.

6
Contributors
10
Replies
48
Views
4 Years
Discussion Span
Last Post by newbie26
Featured Replies
  • 1
    diafol 3,720   4 Years Ago

    That link has all the sample codes you need. Copying an dpasting them here won't make much difference. Try one of them. See what happens. Read More

0

hi nexocentric.
i looked over the site you gave me.but i saw it complicated.
sorry.im kinda new to this.can you please give me sample code?

hope you can help me. thanks again.. :-(

0

Here is some sample code with explanations. Make sure to run and check the output yourself. This is most definitely not the best or most perfect, but it's a good start.

$path = "/path/"; //<-the path that you want
$folderList = array(); //holder for folders
$directories = scandir( realpath($path) ); //adjusts your path for UNIX or Windows and scans a directory
//go through the list and check if it's a directory
foreach( $directories as $folder ) {
    if ( is_dir($path.$folder) ){
        //add if directory
        $folderList[$folder] = $folder; //after this is done folderList for various things
    }
}

Edited by nexocentric: fixed tabbing

1

That link has all the sample codes you need. Copying an dpasting them here won't make much difference. Try one of them. See what happens.

0

hi nexocentric..
i tried the code.. then i put $path="C:/Program Files/"
nothing happens..
sorry..what can you suggest??

thanks :-(

0

Is your computer you are running this code from a windows system? localhost?
Or have you uploaded it to a server, and want to read the dir of the computer that runs your browser?

0
$files = array(  ); // or a class object
$dir = opendir( $name );
while( false !== ($file = readdir($dir)) )
{
  if( $file != '.' && $file != '..' )
  {
    $pop = explode('.',$file);
    $ext = "";
    if(count($pop)>1) $ext = array_pop($pop);
    $files[implode('.',$pop)][] = $ext; // You may want to save other attributes as well, shrug
  }
}
closedir($dir);
0

hi.. its not working.
i already tried this one but it always reads the web server not the other remote server:

<?php
    $ip = 'ip.add.re.ss'; //this is the server i want to connect
    $host = gethostbyaddr( $ip );
    if ( $ip == $host )
        die( 'Unable to resolve hostname from ip '.$ip );

    $path = '//'.$host.'/sharename';


    if ( !is_dir($path) )
        die( $path. ' is not a directory' );

    $dir = opendir($path);
    if ( $dir == FALSE )
        die( 'Cannot read '.$path );

    while (($file = readdir($dir)) !== FALSE)
        echo "filename: $file : filetype: ".filetype( $path.$file)."\n";

    closedir( $dir );


?>

please help me..thanks..

0

What do you mean by "other remote server". You cannot use opendir and readdir across servers (unless you use ftp).

0

other server from network... :-)

i also tried:

<?php
    $ftp_server = "//ip.ad.dre.ss";
    $conn_id = ftp_connect($ftp_server);
    $ftp_user_name = "root";
    $ftp_user_pass = "password";
    $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
    $contents = ftp_rawlist($conn_id, '/');
    for ($i = 0 ; $i < count($contents) ; $i++)
     {
        echo "<li>" . substr($contents[$i],1) . "</li>";
        }
    ftp_close($conn_id);
?>

it still didnt work for me. :-(
i even tried using the hostname in $ftp_server.
also tried with "/" at the end of the $ftp_server.
still cannot connect.

whats wrong?hope you can help me..thanks.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.