Categories > TinyButStrong general >

rekursiv folder and file listing

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: delta
Date: 2009-04-21
Time: 12:52

rekursiv folder and file listing

Hey everybody,

I found tihs handy script to list all files and subdirectories and its content (rekursiv).
But how can I template this?

Code:

<?php

function show_dir( $dir, $pos=2 )
{
    if ( $pos == 2 ) {
        echo "<hr /><pre>";
    }

    $handle = @opendir( $dir );
    if ( is_resource( $handle ) ) {
        while ( ( $file = readdir( $handle ) ) !== false ) {
            if ( preg_match( '~^\.{1,2}$~', $file ) ) {
                continue;
            }

            if ( is_dir( $dir.$file ) ) {
                printf( "% ".$pos."s <b>%s</b>\n", '|-', $file );
                show_dir( $dir.$file.'/', $pos + 3 );
            } else {
                printf( "% ".$pos."s %s\n", '|-', $file );
            }
        }
        closedir($handle);
    }

    if ( $pos == 2 ) {
        echo "</pre><hr />";
    }
}

show_dir( 'templates/' );
$TBS->MergeBlock('blk1',$file_folder_list);

?>


Template:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>TinybutStrong - Folder &amp; file listing</title>
  <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
</head>
<body>

<div id="content">
<h1>(Sub)Folder &amp; File listing</h1>   
        [blk1;block=begin]
        [blk1.val;htmlconv=no]
        [blk1;block=end]       
</div>

</body>
</html>

Thanks for helping me to learn...