Hello
this is first time i`m writing here so sorry for stupid questions or so.
I need to make a program wich will list the directories and subdirectories.
I find something like that here on this mailing list and i have changed it for my own needs.
but now a have this problem:
i want to print first the directories and its subdirectries and first after that a want to list normal files. so i have made some code for sorting the array and put it into the tree program.
now it look like this

#!/usr/bin/perl
use Term::ANSIColor qw(:constants);
$cesta = $ARGV[0];
sub do_dir {
        my $cesta = shift;
        opendir (OBSAH, $cesta);
        my @obsah = readdir(OBSAH);
        closedir(OBSAH);
        $t = $#obsah;
        for ($i= 0 ; $i < $t ; ++$i) {
                 my $filename = $cesta . '/' . $obsah[$i];
                        if ( $obsah[$i]  eq '.' || $obsah[$i]  eq '..' ) {
                        delete ($obsah[$i]);
                        } elsif (-d $filename) {
                                push (@obsah2, $obsah[$i]);
                                delete ($obsah[$i]);
                         } else {
                                push (@obsah3,$obsah[$i]);
                                delete ($obsah[$i]);
                        }
                }
        unshift(@obsahx,@obsah2);
        push(@obsahx,@obsah3);
        foreach my $prvok (@obsahx) {
                                my $filename = $cesta . '/' . $prvok;
                                next if ($prvok eq '.' || $prvok eq '..')
                                 elsif (-d $filename) {
                                         ++$k;
                                         print "|------------" x $k;
                                         print GREEN, "$prvok\n", RESET;
                                         do_dir($filename);
                                        --$k;
                                        }
                                  else {
                                         ++$k;
                                         print "|------------" x $k;
                                         print BLUE,  "$prvok\n", RESET;
                                         --$k;
                                         }
                                  }
}
do_dir($cesta);


where $cesta is path which i write in shell and its path to directory wich i want to make a tree from.
but this source code loops and never ends.
can smbdy help me please?
Thanks a lot.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to