in reply to Re: Rmtree with exclude
in thread Rmtree with exclude

Thank you James!
Your code after few adjustments works like a charm.
#!/usr/bin/perl use strict; use warnings; use File::Slurp; use File::Path qw( remove_tree ); my $dir = "/opt/ssi/cache"; my $err_list = "/home/az/log.txt"; my @dirs = read_dir( $dir ); for (@dirs) { next if ( -f $_ ); if ( $_ !~ /(?:_)/ ) { my $removed = "$dir/$_"; remove_tree( $removed , { verbose => 1, error => \my $err_list, }); print "removed : $removed\n"; } }

Replies are listed 'Best First'.
Re^3: Rmtree with exclude
by james28909 (Deacon) on Dec 02, 2014 at 20:53 UTC
    Awesome man, glad i could help. Though i am sure any of the other examples would have did the trick as well ;)

    Also, you should be very careful with remove_tree, and if possible add in absolute path to folder that you want to delete, that way the path that gets fed to remove tree is the exact folder you want deleted.

    Upon revising this, I deleted a folder in the scripts dir that had the same name of a dir in the test dir (was my mistake for using the same folder name i guess). needless to say it had abunch of my perl scripts in it and now i am having to try to use recovery software to hopefully get them back.