[HOME] 

当社のコマンドラインツールとのインタフェースに Perl スクリプトを使用

English 日本語

 

次の Perl スクリプトは、 Mark Macumber 氏より無料で提供されています。独自のツールをお持ちで、製品に追加したい方はご連絡ください。

基本的に、この Perl スクリプトは、必要なコマンドライン引数を含むバッチファイルを作成し、バッチファイルを起動します。

必要に応じて、$start_dir などを変更できます。

use strict;
use File::Find;
use IO::File;
my $start_dir = "m:\\";

IO::File->new("conversion.bat", "w");
open(FileOut, ">conversion.bat") or die("Can't open file for writing: $!");

find (\&wanted, $start_dir);
sub wanted {
  if (/\.doc$/i)
  {
    # find and replace used for ease of regex for replacing .doc with .pdf
    my $find = ".doc";
    my $replace = ".pdf";

    # set variables for paths to doc file and pdf directory
    my $path = $File::Find::name;
    my $pdfDir = $File::Find::dir;

    # replace .doc with .pdf for the conversion
    my $pdfname = $_;
    $pdfname =~ s/$find/$replace/gi;

    #replace / with \ for the paths
    $path =~ s/\//\\/g;
    $pdfDir =~ s/\//\\/g;

    # print out Convert Doc commands in .bat file
    print FileOut "ConvertDoc /S $path /F9 /T $pdfDir\\$pdfname /C12 \n";
  }
}
close(fileOuT);
system("conversion.bat");