Suppose I create some Windows symbolic links, as in:
rd /s /q source withlink linkdir
mkdir source
mkdir withlink
echo blah > source/myfile
cd withlink
touch blah
mklink mylink ..\source\myfile
@REM mklink /d linkdir ..\source
cd ..
I can delete the directory containing the symlinks in the shell with
rd /s /q withlink
I have the same task to do in a perl script where we currently use cygwin 'rm -rf'. Unfortunately we are using cygwin 1.5 and rm and rm -rf don't work properly in that version on the symbolic links I'd like to use (they delete symbolic link contents instead of the symlinks).
If I try:
use File::Path qw( rmtree ) ;
rmtree( ['withlink'] ) ;
This works nicely, provided I don't have any directory symbolic links (like the one REM'ed out in the create-the-links sequence above), then perl's rmtree ends up behaving like cygwin, and I end up with the directory contents of my original directory deleted.
Does anybody have a suggestion of an alternate perl recursive directory deletion method that I could use. I thought of just a shell callout:
system("rd /s /q withlink") ;
but this requires I test the platform and have different perl code for Windows and Unix.
EDIT: Note that, unlike Unix, unlink() does not work to remove a directory symlink, at least with perl v5.6.0, which is what our build system is currently using. However, rmdir() does work to remove a windows directory symlink.