Hi Monks I have the following snippet of code which creates an MD5 hash of a folder using the Digest::MD5::File module. Ideally I just want to use the Digest::MD5 module but from what I've read it can't MD5 hash a folder. I'm unable to get IT to install the Digest::MD5::File module (slow process of installing and testing software) so how do I go about fixing the bottom piece of code to MD5 hash a folder successfully or can you suggest another way to create a hash of a folders contents using the standard MD5 module.

use Digest::MD5; use Digest::MD5::File; ..... $filemd5->addfile($MD5); my $md5value = $filemd5->hexdigest(); push @md5list,"$md5value,$file"; } my $targetmd5 = $p00path . $p00 . '.md5'; my $MD5 = undef; if (not open ($MD5,'>',$targetmd5)) { print "Could not open $targetmd5 for write,Error: $!\n"; next P00; } my $qcmd5 = Digest::MD5->new(); # Make MD5 Object for checksum print $MD5 "# MD5 File for Optical Media ID $p00\n"; print $MD5 "# ISO created by $name $datestring\n"; foreach my $line (@md5list) { $qcmd5->add($line); print $MD5 "$line\n"; } my $folderMD5 = Digest::MD5::File->new; $folderMD5->adddir($p00path); my $finalmd5 = $folderMD5->hexdigest; print $MD5 "CHECKSUM: $finalmd5\n"; close $MD5; print "Made MD5 file for $p00\n";
My previous code below wasn't creating an MD5 hash of the folder it was creating a hash of the path and the item number...
$filemd5->addfile($MD5); my $md5value = $filemd5->hexdigest(); push @md5list,"$md5value,$file"; } my $targetmd5 = $p00path . $p00 . '.md5'; my $MD5 = undef; if (not open ($MD5,'>',$targetmd5)) { print "Could not open $targetmd5 for write,Error: $!\n"; next P00; } # Make MD5 Object for checksum my $qcmd5 = Digest::MD5->new(); print $MD5 "# MD5 File for Optical Media ID $p00\n"; print $MD5 "#\n"; foreach my $line (@md5list) { $qcmd5->add($line); print $MD5 "$line\n"; } my $finalmd5 = $qcmd5->hexdigest(); print $MD5 "CHECKSUM: $finalmd5\n";

Thanks


In reply to MD5 Hash of a folder query by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.