Why can't I use more than 20 files with Perl script and Windows SendTo?

I'm trying to emulate RapidCRC's ability to check crc32 values ​​in filenames in Windows Vista Ultimate 64-bit. However, it seems I am running into some kind of limitation of the arguments.

I wrote a quick Perl script, created a batch file to invoke it, then placed a shortcut for the batch file in %APPDATA%\Microsoft\Windows\SendTo

This works great when I select about 20 files or less, right click and "submit" my batch script file. However, nothing happens when I choose more than this. I suspect the character or number of arguments is limited somewhere.

I hope I missed something simple and that the solution or workaround isn't too painful.

Literature:

batch file (crc32_inline.bat):

crc32_inline.pl %*

      

Perl notes:

I am using (strawberry) perl v5.10.0

I have C: \ strawberry \ perl \ bin in my path where crc32.bat exists.

perl script (crc32_inline.pl):

#!/usr/bin/env perl

use strict;
use warnings;

use Cwd;
use English qw( -no_match_vars );
use File::Basename;

$OUTPUT_AUTOFLUSH = 1;

my $crc32_cmd = 'crc32.bat';
my $failure_report_basename = 'crc32_failures.txt';
my %failures = ();

print "\n";
foreach my $arg (@ARGV) {

  # if the file has a crc, check to see if it matches the calculated
  # crc.
  if (-f $arg and $arg =~ /\[([0-9a-f]{8})\]/i) {
    my $crc = uc $1;
    my $basename = basename($arg);
    print "checking ${basename}... ";
    my $calculated_crc = uc `${crc32_cmd} "${arg}"`;
    chomp($calculated_crc);
    if ($crc eq $calculated_crc) {
      print "passed.\n";
    }
    else {
      print "FAILED (calculated ${calculated_crc})\n";
      my $dirname = dirname($arg);
      $failures{$dirname}{$basename} = $calculated_crc;
    }
  }
}

print "\nReport Summary:\n";
if (scalar keys %failures == 0) {
  print "  All files OK\n";
}
else {
  print sprintf("  %d / %d files failed crc32 validation.\n" .
                "  See %s for details.\n",
                scalar keys %failures,
                scalar @ARGV,
                $failure_report_basename);

  my $failure_report_fullname = $failure_report_basename;
  if (defined -f $ARGV[0]) {
    $failure_report_fullname
      = dirname($ARGV[0]) . '/' . $failure_report_basename;
  }

  $OUTPUT_AUTOFLUSH = 0;
  open my $fh, '>' . $failure_report_fullname or die $!;
  foreach my $dirname (sort keys %failures) {
    print {$fh} $dirname . "\n";
    foreach my $basename (sort keys %{$failures{$dirname}}) {
      print {$fh} sprintf("  crc32(%s) basename(%s)\n",
                          $failures{$dirname}{$basename},
                          $basename);
    }
  }
  close $fh;
  $OUTPUT_AUTOFLUSH = 1;
}

print sprintf("\n%s done! (%d seconds elapsed)\n" .
              "Press enter to exit.\n",
              basename($0),
              time() - $BASETIME);
<STDIN>;

      

+2


source to share


1 answer


I recommend simply placing the shortcut in your script in the Submit directory, rather than doing it through a batch file (which is subject cmd.exe

to command line length restrictions ).



+1


source







All Articles