Leser: 1
|< 1 2 3 4 >| | 36 Einträge, 4 Seiten |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use strict;
use warnings;
use Digest::MD5;
use Cwd;
use File::Find;
my $dir = getcwd;;
my @files;
find(\&get_dir,$dir);
for my $file(@files)
{
print $file,"\n";
my $md5 = Digest::MD5->new;
$md5->add($file);
my $digest = $md5->hexdigest;
print "Digest is $digest\n";
}
sub get_dir
{
push(@files,$File::Find::name) if(-f $File::Find::name);
}
Quote\n\nThis is useful when calculating checksum for files:
use Digest::MD5;
my $file = shift || "/etc/passwd";
open(FILE, $file) or die "Can't open '$file': $!";
binmode(FILE);
$md5 = Digest::MD5->new;
while (<FILE>) {
$md5->add($_);
}
close(FILE);
print $md5->b64digest, " $file\n";
Or we can use the builtin addfile method for more efficient reading of the file:
use Digest::MD5;
my $file = shift || "/etc/passwd";
open(FILE, $file) or die "Can't open '$file': $!";
binmode(FILE);
print Digest::MD5->new->addfile(*FILE)->hexdigest, " $file\n";
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
use strict;
use warnings;
use Digest::MD5;
use Cwd;
use File::Find;
my $dir = getcwd;
my @files;
find(\&get_dir,$dir);
for my $file(@files)
{
print $file,"\n";
my $md5 = Digest::MD5->new;
open FILE, $file;
binmode(FILE);
while(<FILE>) { $md5->add($_); }
my $digest = $md5->hexdigest;
close FILE;
print "Digest is $digest\n";
}
sub get_dir
{
push(@files,$File::Find::name) if(-f $File::Find::name);
}
QuoteDigest::SHA
Perl extension for SHA-1/224/256/384/512
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# ------------------------------------------------------------------
# loaded modules
# ------------------------------------------------------------------
use strict;
use warnings;
use Digest::MD5;
use Cwd;
use File::Find;
use threads;
use threads::shared;
#
#
# ------------------------------------------------------------------
# start threads
# ------------------------------------------------------------------
my $StopDotPrintFlag : shared;
sub DotPrintThread
{
my ($Interval, @Trash) = @_;
use IO::Handle;
autoflush STDOUT 1;
my $IntervalCount=0;
while ($StopDotPrintFlag != 2)
{
if ($StopDotPrintFlag == 1)
{
print STDOUT ".";
}
$IntervalCount++;
sleep $Interval;
}
return $IntervalCount;
}
#
#
# ------------------------------------------------------------------
# start programm
# ------------------------------------------------------------------
my $dir = getcwd;
my @files;
find(\&get_dir,$dir);
$StopDotPrintFlag = 0;
my $Interval = 1;
my $DotPrintThread = threads->new(\&DotPrintThread, $Interval);
$StopDotPrintFlag = 1;
for my $file(@files)
{
my $md5 = Digest::MD5->new;
open FILE, $file;
binmode(FILE);
while(<FILE>) { $md5->add($_); }
my $digest = $md5->hexdigest;
close FILE;
open(my $fh, ">>md5_check.txt") or die $!;
print $fh "\nDigest is $digest for $file\n";
close $fh;
}
$StopDotPrintFlag = 2;
my $NumberOfPrintedDots=$DotPrintThread->join;
print "\napplied time was ".$NumberOfPrintedDots*$Interval." seconds\n";
sub get_dir
{
push(@files,$File::Find::name) if(-f $File::Find::name);
}
|< 1 2 3 4 >| | 36 Einträge, 4 Seiten |