#!/usr/bin/perl -w # # CD Check - Compares files burned to CD with the original files. # # # This utility should be used directly after burning the CD # and before archival to check if the data on the CD is # legitimate or some kind of buffer error caused it to become # corrupt or changed. # # Some CD Recording software contain such a utility by default # for example Nero Burning ROM, but some don't. There's where # this script comes in handy. # ################################################################## use strict; use File::Find; use Digest::MD5; use vars qw/$base1 $base2 @errors/; get_path($base2, "Enter path to original files: "); get_path($base1, "Enter CD path: "); find(\&check, $base1); if (@errors > 0) { print "\n\n\nGot ", scalar @errors, ".\nThe following files were changed, possibly a badly b +urned CD.\n\n"; print join "\n", @errors, "\n"; } else { print "\n====================\n"; print "CD burned correctly.\n"; print "====================\n\n"; } # END sub get_path { { print $_[1]; chomp($_[0] = <STDIN>); unless (-d $_[0]) { print "Not a directory\n"; redo; } # to save some headache later, let's # standardize the path. $_[0] =~ s[\\][/]g; $_[0] .= '/' unless $_[0] =~ m{/$}; } } sub check { return unless -f $File::Find::name; # don't check folders. my $path = $File::Find::name; $path =~ s/^\Q$base1\E//; my $file2 = $base2 . $path; # that's the file in the original +folder. print '=' x 50 , "\n+ Checking $File::Find::name\n\t"; my $MD5_1 = get_md5($File::Find::name); print $MD5_1, "\n"; my $MD5_2 = get_md5($file2); unless ($MD5_1 eq $MD5_2) { warn "\n\n*** Different files \n$MD5_1 * $File::Find:: +name\n$MD5_2 * $file2\n\n"; push @errors, $File::Find::name; } } sub get_md5 { my $file = shift; open FILE, "<", $file or die "Can't open $file : $!\n"; binmode FILE; return Digest::MD5->new->addfile(*FILE)->hexdigest; }

In reply to cdcheck by Chady

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.