Thread Alle Dateien eines Formats suchen... (13 answers)
Opened by KarlaCluft at 2013-01-27 18:54

topeg
 2013-01-27 21:21
#165213 #165213
User since
2006-07-10
2611 Artikel
BenutzerIn

user image
Mit CPAN: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 CPAN: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);



CPAN:File::LibMagic hat die besseren Ergebnisse. CPAN:File::MMagic ist weiter verbreitet.

View full thread Alle Dateien eines Formats suchen...