Suppose I created some Windows symbolic links, for example:
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 symlinks in the shell using
rd /s /q withlink
I have the same task to do in a perl script, where we are currently using cygwin 'rm -rf'. Unfortunately, we use cygwin 1.5, and rm and rm -rf do not work properly in this version on symbolic links that I would like to use ( they remove symbolic links instead of symbolic links ).
If I try:
use File::Path qw( rmtree ) ; rmtree( ['withlink'] ) ;
This works well if I don't have any symbolic directory links (such as REM'ed in the create-the-links sequence above), then perl rmtree behaves like cygwin, and I get the contents of the directory of my source directory deleted.
Does anyone have a suggestion of an alternative method to delete a recursive directory that I could use. I was only thinking of a shell callout:
system("rd /s /q withlink") ;
but this requires me to test the platform and have different perl code for Windows and Unix.
EDIT: Please note: unlike Unix, unlink () does not work to remove a symbolic link to a directory, at least with perl v5.6.0, which is used by our build system. However, rmdir () does work to remove the symbolic link of the Windows directory.
Peeter joot
source share