Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Iam using the "File::Find" to search my NT directories. When it runs into a directory I have no permissions to it gives me the following message (even though "/Dir/dirOne" exists I dont have permissions to read it):
Cant opendir(/Dir/dirOne): Invalid argument
I was hoping to write my own message to say: "No permissions in this directory". I can redirect the message into STDERR but I would rather output the message but with my own personlized message. Is this possible?

Replies are listed 'Best First'.
Re: Changing output message
by BrowserUk (Patriarch) on Jul 01, 2003 at 01:43 UTC

    Try adding this prior to calling File::Find

    $SIG{__WARN__} = sub{ print STDERR "No permission for directory:$1\n" + if $_[0] =~ m[\(([^\)]+)\)]; } find ..... $SIG{__WARN__} = undef; ...

    See perlvar:%SIG and the list of see also's at the bottom of that section for further information/explaination.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller