list folders script

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • dlite922
    replied
    see php.net/glob

    and php.net/filemtime

    get the directory files with glob. store the filename and the file modified time in an array. Then reverse sort the array: php.net/arsort

    Isn't PHP great? The manual gives you all these fantastic functions to do anything you want.



    Dan

    Leave a comment:


  • richard11259375
    replied
    Thanks for sharing your script, Roverdonk. How do I get it to list the folders / links in reverse order, so that the newest is on the top?

    Thanks.

    R

    Leave a comment:


  • imran007
    replied
    Originally posted by coolsti
    Nice little script. Would be only a small amount of effort to modify it (with a third argument) to let the user specify how many levels down in the directory tree the function (and it's recursive calls) would go.

    To sort the results, I would suppose I would modify all the echo statements so that instead of directly printing out the results to the remote user as the "dh" list is retrieved, I would store the results intermediately in arrays. Then when all the files and subdirectories have been traversed, sort the arrays one by one alphabetically and do the "echo" printouts to the user.
    Do you any sample code I can use?

    Leave a comment:


  • coolsti
    replied
    Nice little script. Would be only a small amount of effort to modify it (with a third argument) to let the user specify how many levels down in the directory tree the function (and it's recursive calls) would go.

    To sort the results, I would suppose I would modify all the echo statements so that instead of directly printing out the results to the remote user as the "dh" list is retrieved, I would store the results intermediately in arrays. Then when all the files and subdirectories have been traversed, sort the arrays one by one alphabetically and do the "echo" printouts to the user.

    Leave a comment:


  • imran007
    replied
    Hi,

    Is there a way to display the listing alphabetically?

    Regards
    Imran

    Leave a comment:


  • ronverdonk
    replied
    Just take out the recursive part, i.e. line 28
    [php]getDirectory( "$path/$file", ($level+1) ); [/php]
    anf it will only show the folders under the dir you specified.

    Ronald

    Leave a comment:


  • 7effrey
    replied
    Originally posted by ronverdonk
    Happen to have one of those 'on-the-shelf'
    [php]
    <?php
    // Your start directory
    getDirectory('./');

    function getDirectory( $path = '.', $level = 0 )
    {
    // Directories to ignore when listing output.
    $ignore = array( '.', '..' );

    // Open the directory to the handle $dh
    $dh = @opendir( $path );

    // Loop through the directory
    while( false !== ( $file = readdir( $dh ) ) )
    {
    // Check that this file is not to be ignored
    if( !in_array( $file, $ignore ) )
    {
    // Indent spacing for better view
    $spaces = str_repeat( '&nbsp;', ( $level * 5 ) );

    // Show directories only
    if(is_dir( "$path/$file" ) )
    {
    // Re-call this same function but on a new directory.
    // this is what makes function recursive.
    echo "$spaces<a href='$path/$file/index.php'>$fil e</a><br />";
    getDirectory( "$path/$file", ($level+1) );
    }
    }
    }
    // Close the directory handle
    closedir( $dh );
    }
    ?>
    [/php]
    Ronald
    Hi again

    i noticed this:
    // Directories to ignore when listing output.
    $ignore = array( '.', '..' );

    using this script as provided shows some of my folders which lies inside the folder which names is displayed. What is the kind of "code" that i have to add to $ignore = array( '.', '..' ); to ignore showing these folders?

    Example:
    Name-on-folder
    - foldder-inside-Name-on-folder


    Noticed that adding "folder-inside" will remove showing the folder, but because i have so many folders, i want to write a generel thing that ignores all the folders
    $ignore = array( '.', '..', "folder-inside" );

    Leave a comment:


  • ronverdonk
    replied
    Happen to have one of those 'on-the-shelf'
    [php]
    <?php
    // Your start directory
    getDirectory('./');

    function getDirectory( $path = '.', $level = 0 )
    {
    // Directories to ignore when listing output.
    $ignore = array( '.', '..' );

    // Open the directory to the handle $dh
    $dh = @opendir( $path );

    // Loop through the directory
    while( false !== ( $file = readdir( $dh ) ) )
    {
    // Check that this file is not to be ignored
    if( !in_array( $file, $ignore ) )
    {
    // Indent spacing for better view
    $spaces = str_repeat( '&nbsp;', ( $level * 5 ) );

    // Show directories only
    if(is_dir( "$path/$file" ) )
    {
    // Re-call this same function but on a new directory.
    // this is what makes function recursive.
    echo "$spaces<a href='$path/$file/index.php'>$fil e</a><br />";
    getDirectory( "$path/$file", ($level+1) );
    }
    }
    }
    // Close the directory handle
    closedir( $dh );
    }
    ?>
    [/php]
    Ronald

    Leave a comment:


  • 7effrey
    started a topic list folders script

    list folders script

    Hi

    Does anyone know how to make a script that list the folders in a specific directory, but when the list is made it must be possible to click on it like a link so people can be redirected, but not to the folder, but to a special file inside the folder.

    example:
    - list the names on the folders from root
    - the names appear in a link form (<a href=' ' </a>) on my php page
    - when i click i shall be redirected to one-of-the-folder-names/index.php

    thank you for paying attention, i hope you can help
Working...