#!/usr/bin/perl
use autodie;
use utf8;
use Encode qw(decode encode);
sub del_dir{
my $path = shift @_;
my @files = <$path/* $path/.*>;
my @dirs = (); # save empty directory
for( @files ){
next if /.{1,2}$/g; # skip ./. ./.. directories
(-d -e $_) ? push(@dirs, $_) && del_dir($_)
: unlink $_;
};
for(@dirs){
rmdir $_ if -e $_;
};
rmdir $path;
};
del_dir(shift @ARGV);
执行脚本
λ perl main.pl ./src