Thanks to everyone who wrote concerning my problem unlinking a file from
within the script where it was created.  Between the time I posted and the
time I got your responses, I had already tried out some of the things you
suggested.  Unfortunately, the problem seems more complex and I haven't
solved it yet.  Here's what I tried:

1.  Ruled out problem of backward-slashes by simply trying to unlink the
file without the long path.  No luck.

2.  Ruled out possibility that problem was caused by wordspaces in Windows
file names by replacing all spaces with underscores -- both in filename and
directory name.  No luck.

3.  Within same Perl script, created a new plain-text file by opening a
filehandle, printing one line of text and closing the filehandle.  I then
succeeded in unlinking this new file.

4.  Examined permissions of both new plain-text file and one with which
having unlink problems.  Permissions identical:  0666.

5.  One correspondent suggested off-list that the reason I couldn't unlink
the target file was that it was still open in the script.  I had clearly
closed the filehandle through which I was subsequently reading the target
file, but there is one sense in which this file may not have been completely
'closed'.  Read on.

6.  Now believe problem stems from *how* the target file was originally
created.  It was created by opening a Microsoft Word file and saving it as a
plain-text document.

    my $Word = Win32::OLE->new('Word.Application', 'Quit');
    $Word->{'Visible'} = 1;
    $Word->Documents->Open($fullin)
        || die("Unable to open $fullin", Win32::OLE->LastError());

    $Word->ActiveDocument->SaveAs({
        FileName   => $fullout,
        FileFormat => wdFormatText,
    });

where $fullin and $fullout are the full paths for the input and output
files.  (I got this code by searching in the archives of this mailing list
for a couple of hours.)

This code successfully creates the target file and closes the MS Word
process.  I can then open a handle to the target file, read and parse its
contents, and close that handle.  But when I try to execute an 'unlink' on
this file (or, as well, a 'rename'), I still get the message saying I don't
have permission to unlink the file.  I can do everything I want with this
file except get rid of it from within the same Perl script once I no longer
need it.

When I run the script under the 'use diagnostics' pragma, I get "Uncaught
exception from user code at line XX".  Hence, I infer that the Win32::OLE
process is throwing an uncaught exception that is for some reason
interfering with subsequent system-level operations on the file.

Does anyone have any idea how I can catch this 'uncaught exception' and
dispose of it so that I can unlink the target file?  Thanks; will respond
after YAPC.

Jim Keenan


_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to