1 2 3 4 5 6 7 8 9 10 11 12 13
use strict; use warnings; my $path='/home/backup/'; opendir(my $dh, $path) or die("Can't open dir $path"); while( my $file=readdir($dh) ) { my $file_path=File::Spec->join($path,$file); next unless -f $file_path; print "$1\n" if($file=~/([^.]+)$/); } closedir($dh);
1 2 3 4 5 6 7 8 9 10 11 12 13 14
use strict; use warnings; my $path='/home/backup/'; opendir(my $dh, $path) or die("Can't open dir $path"); while( my $file=readdir($dh) ) { my $file_path=File::Spec->join($path,$file); next unless -f $file_path; my $ending=(split(/\./,$file))[-1]; print "$ending\n"; } closedir($dh);
1 2 3 4 5 6 7 8 9 10 11 12 13 14
use strict; use warnings; use File::LibMagic; my $mm = File::LibMagic->new(); my $path='/home/backup'; for my $file (glob("$path/*")) { next unless -f $file; my $type=$mm->checktype_filename($file); $type=(split('[/;]',$type))[1]; print "$type\n"; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14
use strict; use warnings; use File::MMagic; my $mm = File::MMagic->new(); my $path='/home/backup/'; for my $file (glob("$path*")) { next unless -f $file; my $type=$mm->checktype_filename($file); $type=(split('[/;]',$type))[1]; print "$type\n"; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
use strict; use warnings; use File::LibMagic; use File::Spec; my $mm = File::LibMagic->new(); my $path='/home/backup/'; opendir(my $dh, $path) or die("Can't open dir $path"); while( my $file=readdir($dh) ) { my $file_path=File::Spec->join($path,$file); next unless -f $file_path; my $type=$mm->checktype_filename($file_path); $type=(split('[/;]',$type))[1]; print "$type\n"; } closedir($dh);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#! /usr/bin/perl use strict; use warnings; # this is findmp3 # findmp3 DIR [DIR2] [DIR3] use File::Find::Rule; my @dirs = @ARGV; if ( !@dirs ) { warn "No directories specified! Using '.' for search.\n"; @dirs = ( '.' ); } my @files = File::Find::Rule->file() ->name('*.[mM][pP]3') ->in( @dirs ); print "Found these files: \n", join "\n", @files;
1 2 3 4 5 6 7
# wie zuvor gezeigt, @files fuellen # ... my @files = File::Find::Rule->... for my $file ( @files ) { # jede einzelne Datei betrachten und verarbeiten; der Pfad dazu sollte in $file stehen # ... }
1 2 3
opendir (my $DIR, $path); my @musik = grep {/\.mp3/i} readdir ($DIR); closedir ($DIR);
2013-01-28T12:34:45 GUIfreundAchtung: Liefert die reinen Dateinamen, nicht die kompletten Pfade.