home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1998 July / Vpr9807a.iso / get_md5sums.pl < prev    next >
Perl Script  |  1998-05-01  |  1KB  |  66 lines

  1. #!/usr/bin/perl
  2.  
  3. $count=0;
  4. $limit=0;
  5.  
  6. # process the command line arguments.
  7. $output = "";
  8. $input = "";
  9. $outputFile = "MD5SUMS";
  10. $inputDir = ".";
  11.  
  12. for($i = 0; $i <= $#ARGV; $i++)
  13. {
  14.    if($output)
  15.    {
  16.       $outputFile = $ARGV[$i];
  17.       $output = "";
  18.       next;
  19.    }
  20.  
  21.    if($input)
  22.    {
  23.       $inputDir = $ARGV[$i];
  24.       $inputDir .= "/" unless $inputDir =~ /\/$/;
  25.       $input = "";
  26.       next;
  27.    }
  28.  
  29.    if($ARGV[$i] eq "-o")
  30.    {
  31.       $output = "true";
  32.    }
  33.    elsif($ARGV[$i] eq "-d")
  34.    {
  35.       $input = "true";
  36.    }
  37.    else
  38.    {
  39.       print "usage: $0 [-o output_file] [-d input_directory]\n";
  40.       exit(0);
  41.    }
  42. }
  43.  
  44. open(ofp,">$outputFile");
  45. open(lfp,"find $inputDir -type f |");
  46. while(<lfp>) {
  47.     chop;
  48.     $filename=$_;
  49.     print "Processing [$filename]...\n";
  50.     $count++;
  51.     open(ifp,"md5sum $filename |");
  52.     while(<ifp>) {
  53.     chop;
  54.     print ofp "$_\n";
  55.     }
  56.     close ifp;
  57.     if (($limit > 0) && ($count == $limit)) {
  58.     close lfp;
  59.     close ofp;
  60.     die "Finished at $limit\n";
  61.     }
  62. }
  63. close lfp;
  64. close ofp;
  65. print "\nFiles: $count\n";
  66.