Best Directory Tree



Hi

Can suggest the best approach to create directory tree using the CTREE widget.
I'd like to make it fast and efficient.  The problem I ran into was setting up
the [+] subdir indicators when children exist.

I setup a search where the first subdir of a folder would be found, then that
folder would be scanned for its first subdir,
and so on until no more subdirs were found.  Then when the folder was expanded,
the expanded routine would
skip the first directory, and process all remaining subdirs for that parent. 
This seems to work ok, but there are 
certain directories that cause a problem and end up not getting added.

The code below works, but certain files cause a problem and get added to the
root node.  It only occurs in a few directories:
i.e. 
You selected George  Path: /home/budman/Projects/George-0.2/lib/George
You selected 00         Path: /home/budman/netscape6/budman/Cache/00

Could there be a file setting that is throwing off the   -d  function?

Thanks.
Budman

-------------------------------------
sub add_ctree_leaf
{
        my ( $ctree, $parent, $leaf_data, $spacing, $leafmode, $expand ) = @_;
        my $new_leaf;
        
        $new_leaf = $ctree->insert_node( $parent, undef, 
                        [$leaf_data], $spacing, 
                        $fclose_pixmap, $fclose_mask, 
                        $fopen_pixmap, $fopen_mask, 
                        $leafmode, $expand );
        return $new_leaf;
}

chdir($rootdir);
foreach $folder ( <*> ) 
{            
        if ( -d $folder ) {
                $path = $rootdir . $folder;
                $tree_leaf = add_ctree_leaf( $ctree, $root_leaf,
                                                        $folder, 5, $notnode,
$notexpanded );
                $ctreenodes{$tree_leaf} = {     path => $path, expanded =>
$false };

                $firstchild = has_subs( $path );                        
                while ( defined($firstchild) ) {                        
                        $path = $path . "/" . $firstchild;
                        $subdir_leaf = add_ctree_leaf( $ctree, $tree_leaf,
                                                        $firstchild, 5,
$notnode, $notexpanded );
                        $ctreenodes{$subdir_leaf} = {path => $path,    
expanded => $false };
                        $firstchild = has_subs( $path );
                        $tree_leaf = $subdir_leaf;
                }               
        }               
}            
         
sub has_subs
{
    my ( $dir ) = @_;
    my $file;
    my @dirpath = ();
        
    foreach $file ( <$dir/*> )
    {
                if ( -d $file && ! -l $file ) {
                        (@dirpath) = split("/",$file);
                        return $dirpath[$#dirpath];
                }
    }        
    return;
}      






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]