- 论坛徽章:
- 0
|
修改后的代码,现在应该能处理文件名包含空格的情况了,请指正。
#!/usr/bin/perl
#Decompile .chm file to html format.
#Author Huang Yong.
#2007-9-10
#Usage:progname filename1 filename2 ...
#可使用通配符
use File::Copy;
use File::Basename;
sub decompiler
{
my $chmfile = $_[0];
my $tmp = "temp";
while (-e "$tmp.chm" or -d $tmp){
my $i=1;
$tmp = $tmp.$i;
$i++;
}
die "Cannot open file $chmfile" unless (-e $chmfile);
copy($chmfile,"$tmp.chm") or die "Copy failed: $!";
mkdir ("$tmp") or die "Cannot create temp!";
`hh.exe -decompile $tmp $tmp.chm`;
my $tm = basename($chmfile);
my $html_dir;
if ($tm =~ m@(.+)\.chm@i){
$html_dir = $1;
}
move("$tmp",$html_dir);
unlink ("$tmp.chm");
}
foreach(@ARGV){
my @chmfile;
if(m@[*?[]]@){
@chmfile =glob($_);
}
else{
push(@chmfile,$_);
}
foreach $file(@chmfile){
print "正在反编译 $file,请稍候...\n";
decompiler($file);
print "文件$file编译完成。\n"
}
} |
|
|