| Mark Shellenberger 2004-12-22, 9:00 pm |
| Long time lurker, first time poster...please be gentle.
I am attempting to move through a directory, pull out only files of a
..fin extension (which is Word document format), save each one as .rtf
(Rich Text Format). I'd also like to be able to run some predefined
macros on the files, but I thought just being able to save was a good
place to start.
Currently I get an error stating 'Can't call method "SaveAs" on an
undefined value'.
If someone could point me to some clearer text on Win32::OLE than the
stuff that ASPN, CPAN and Oreilly's Win32 or Nutshell book I'd greatly
appreciate it. If you could tell me what stupid thing I am missing this
time that would be great too.
Here's the code:
#usr/bin/perl
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Word';
$articleDirName = "c:\\work\\test\\psq\\test\\";
unless (opendir(DIR, $articleDirName)) {
warn "Can't open $articleDirName\n";
closedir(DIR);
exit(1);
}
foreach (readdir(DIR))
{
next if $_ eq '.' || $_ eq '..';
$path = "$articleDirName$_";
if (-f $path){
if ($path =~ /\.fin/i){
$doc = Win32::OLE->GetObject($path);
$fileName = $path . ".rtf";
print "$fileName\n";
$doc->ActiveDocument->SaveAs({FileName => $fileName,
FileFormat => wdFormatRTF})
}
undef $doc;
undef $path;
undef $fileName;
}
}
|