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

I am trying to delete a UNC directory on Windows. I have found ways to do this using system commands, but I would prefer to do this within Perl. I have tried rmtree, and I tried using finddepth where I unlink files and rmdir empty directories. unlink works in this latter case but rmdir does not. Any suggestions?

Replies are listed 'Best First'.
Re: How to delete UNC directory on Windows
by ikegami (Patriarch) on Jan 28, 2008 at 23:18 UTC

    rmdir works fine for me. What error does rmdir return?

    C:\>dir /s/b test C:\test\sub C:\test\sub\a C:\>perl -e"unlink('//tribble05/c$/test/sub/a') or die $!" C:\>dir /s/b test C:\test\sub C:\>perl -e"rmdir('//tribble05/c$/test/sub') or die $!" C:\>dir /s/b test

    Update: I meant to say: Are you sure you aren't trying to remove a directory in which you are current chdired?

Re: How to delete UNC directory on Windows
by BrowserUk (Patriarch) on Jan 28, 2008 at 22:34 UTC
    I have found ways to do this using system commands, but I would prefer to do this within Perl

    Why? Do you have lots of UNC paths to remove? This:

    perl -MTime::HiRes=time -wle"print time; system q[rd /s /q \\.\test\delete_this]; print time; 1201559494.81249 1201559494.82497

    Takes all of 12 milliseconds to execute and consumes a whole extra 2k* of ram for that brief period.

    *Assuming you started the script from a command line.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.