On Tue, Jul 10, 2001 at 09:02:21AM -0400, Craig Moynes/Markham/IBM wrote:
> I am having some difficulty understanding your question.
> If you just want to modify this script so that it does not die if the
> directory contains files change the following:
> 
> [snip]
> >    if ((-d $Name) and ($Name =~ /^[A-Z]+$/)) {rmdir $Name or die $!};
> [snip]
> Change this line to:
> if ((-d $Name) and ($Name =~ /^[A-Z]+$/)) {rmdir $Name};

That does solve the immediate problem, but introduces a new one: if the
directory could not be removed for some other reason the script continues
on, regardless.  This may or may not be desired.

If it isn't desired then checking the error value would be appropriate:

    use Errno qw(EEXIST ENOTEMPTY);

    if (-d $Name && $Name =~ /^[A-Z]+$/) {
        if (not rmdir($Name) && not ($! == EEXIST || $! == ENOTEMPTY)) {
            die("Unable to delete directory \"$Name\": \l$!.\n");
        }
    }

This may have to be adapted to work in your environment, depending on what
rmdir returns when it can't delete a non-empty directory.  You may even only
need the ENOTEMPTY test; I included the EEXIST test because that's what
rmdir(2) is documented to return on my HP-UX system in this event.

 
Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

Reply via email to