O
Orion93
Hello,
My script is good (I use a grep rather than a glob) but I'm not still able
to make it function on a continuation of folders.
I know that it is necessary to use the principle of recursivity but that
exceeds me completely!
What I would like, it returned the file c:\toto \ and which it will count
the number of lines of all the files having the extension toto1 being in
the tree structure depending of toto.
Could you indicate me the principle or the function to be used.
Here my current script:
#!/usr/bin/perl
use strict;
use warnings;
use Tk;
use diagnostics;
use Tk::Entry;
my $main = MainWindow -> new;
$main -> title("Test 1");
$main -> Label(-text=>"To:")->pack();
my $toto = $main -> Entry()->pack(-padx=>5);
$main -> Label(-text=>"Extension:")->pack();
my $toto1 = $main -> Entry(-width=>4)->pack(-padx=>5);
$main -> Label(-text=>'Result on c:\result.txt')->pack(-side=>'bottom',-
pady=>1);
$main->Button(-text=>'Ok',-command=>\&recupPages)->pack(-side=>'left',
expand=>1,-pady=>5);
$main->Button(-text=>'Close',-command=>sub {exit;})->pack(-side=>'right',
expand=>1,-pady=>1);
MainLoop();
sub recupPages
{
## Recover fields
my $dir=$toto->get();
my $ext=$toto1->get();
## Created a list of files with toto1 extension
opendir(DIR,$dir) or die "$!\n";
my @files = grep { /\.$ext$/ } readdir( DIR );
closedir( DIR );
## Foreach files
foreach (@files) {
open (SORTIE,">> c:\\result.txt");
open(PL,"$dir/$_") or die "$!\n";
my @lines = <PL>;
close(PL);
print SORTIE "Folder: $dir Files: $_ ".@lines." \n";
}
}
My script is good (I use a grep rather than a glob) but I'm not still able
to make it function on a continuation of folders.
I know that it is necessary to use the principle of recursivity but that
exceeds me completely!
What I would like, it returned the file c:\toto \ and which it will count
the number of lines of all the files having the extension toto1 being in
the tree structure depending of toto.
Could you indicate me the principle or the function to be used.
Here my current script:
#!/usr/bin/perl
use strict;
use warnings;
use Tk;
use diagnostics;
use Tk::Entry;
my $main = MainWindow -> new;
$main -> title("Test 1");
$main -> Label(-text=>"To:")->pack();
my $toto = $main -> Entry()->pack(-padx=>5);
$main -> Label(-text=>"Extension:")->pack();
my $toto1 = $main -> Entry(-width=>4)->pack(-padx=>5);
$main -> Label(-text=>'Result on c:\result.txt')->pack(-side=>'bottom',-
pady=>1);
$main->Button(-text=>'Ok',-command=>\&recupPages)->pack(-side=>'left',
expand=>1,-pady=>5);
$main->Button(-text=>'Close',-command=>sub {exit;})->pack(-side=>'right',
expand=>1,-pady=>1);
MainLoop();
sub recupPages
{
## Recover fields
my $dir=$toto->get();
my $ext=$toto1->get();
## Created a list of files with toto1 extension
opendir(DIR,$dir) or die "$!\n";
my @files = grep { /\.$ext$/ } readdir( DIR );
closedir( DIR );
## Foreach files
foreach (@files) {
open (SORTIE,">> c:\\result.txt");
open(PL,"$dir/$_") or die "$!\n";
my @lines = <PL>;
close(PL);
print SORTIE "Folder: $dir Files: $_ ".@lines." \n";
}
}