![]() |
![]() |
2 Einträge, 1 Seite |
1
2
3
4
5
6
7
use Cwd;
$MyPlace = cwd();
opendir(DIR, $MyPlace)|| die "Error";
while ( my $File = readdir(DIR)) {
push(@Files, $File) if (!-d $File && $File =~/I/i);
}
closedir (DIR);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#!/usr/bin/perl use strict; use warnings; use CGI qw( :standard ); use File::Spec::Functions; use Cwd; my $cgi = CGI->new(); my $index = $cgi->param('index'); my @files = find_files_by_index( $index ); print "index: $index\n@files", $/; sub find_files_by_index { my $idx = shift; my $dir = cwd(); my @files = (); opendir my $dh, $dir or die "$dir: $!\n"; while ( my $file = readdir $dh ) { my $fullpath = catfile( $dir, $file ); if ( !-d $fullpath and $file =~ m/_${idx}.[^.]+\z/ ) { push @files, $file; } } closedir $dh; return @files; }
Quote> dir
bla_I.xls blubb_i.xls nix_is.txt skript.pl
> perl skript.pl index=I
index: I
bla_I.xls
> perl skript.pl index=is
index: is
nix_is.txt
>
![]() |
![]() |
2 Einträge, 1 Seite |