[英]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. 我正在尝试模仿RapidCRC在Windows Vista Ultimate 64位文件名中检查crc32值的功能。 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
我编写了一个快速的Perl脚本,创建了一个批处理文件来调用它,然后在
%APPDATA%\\Microsoft\\Windows\\SendTo
放置了该批处理文件的快捷方式
This works great when I select about 20 files or less, right-click and "send to" my batch file script. 当我选择约20个或更少的文件,右键单击并“发送到”我的批处理文件脚本时,这非常有用。 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.bat): 批处理文件(crc32_inline.bat):
crc32_inline.pl %*
Perl notes: Perl注意:
I'm using (strawberry) perl v5.10.0
我正在使用(草莓)perl v5.10.0
I have C:\\strawberry\\perl\\bin in my path, which is where crc32.bat exists.
我的路径中有C:\\ strawberry \\ perl \\ bin,这是crc32.bat所在的位置。
perl script (crc32_inline.pl): perl脚本(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>;
我建议您仅将脚本的快捷方式放在“发送到”目录中,而不要通过批处理文件来完成(这受cmd.exe
对命令行长度的限制)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.