[HOME]

Using PERL Script To Interface With
 our Command Line Tools

English 日本語

The PERL script below was supplied freely by Mark Macumber.  If you too have a unique contribution that you would like to add, please

Basically, it constructs a batch file with the necessary command line arguments, then launches the batch file.

You may want to change some things around if need be, like the $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");