in reply to deleting windows subdirectories

Try
use strict; use File::Find; my $workspace = "c:/foo/bar"; find \&delFiles, $workspace; sub delFiles { if(-f) { # unlink $File::Find::name or die "Unable to delete file: $!"; print "$File::Find::name"; } }
The print is there for testing purposes. To make it work, you'll just need to uncomment the unlink.
Update: I forgot to die and added it based on grinder's suggestion.

Replies are listed 'Best First'.
Re:x2 deleting windows subdirectories
by grinder (Bishop) on Jun 04, 2002 at 18:12 UTC

    That's not going to work and you're not going to have any idea why, because you're not attempting to check whether the system call (unlink) fails, and if so, for what reason ($!).

    The code will try to delete a directory first, before attempting to delete the files within said directory. At the very least, it should do a depth first search. Even so, be careful about the . and .. entries.

    Use the rmtree approach instead.


    print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u'
      The unlink on the directory will only be tried if it read
      unless(-f){ unlink $File::Find::name; }
      The if(-f) prevents you from deleting anything but files. That means the directories are left alone. True, I should have a die, but it does work, and I use similar code regularly.