开发者

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

I'm trying to emulate RapidCRC's ability to check crc32 values within filenames on Windows Vista Ultimate 64-bit. However, I seem to be running into some kind of argument limitation.

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

This works great when I select about 20 files or less, right-click and "send to" my batch file script. However, nothing happens at all when I select more than that. I suspect there's a character or number of arguments limit somewhere.

Hopefully I'm missing something simple and that the solution or a workaround isn't too painful.

References:

batch file (crc32_inline开发者_如何学C.bat):

crc32_inline.pl %*

Perl notes:

I'm using (strawberry) perl v5.10.0

I have C:\strawberry\perl\bin in my path, which is 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>;


I will recommend just putting a shortcut to your script in the "Send To" directory instead of doing it via a batch file (which is subject to cmd.exes limits on command line length).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜