Thread Alle Dateien eines Formats suchen...
(13 answers)
Opened by KarlaCluft at 2013-01-27 18:54
Mit File::LibMagic:
Code (perl): (dl
)
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"; } Oder mit File::MMagic: Code (perl): (dl
)
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"; } Das Lesen mit opendir: Code (perl): (dl
)
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); File::LibMagic hat die besseren Ergebnisse. File::MMagic ist weiter verbreitet. |