+ }
+
+ local *DIR;
+ # if we can't open the dir, just skip to the next one.
+ opendir DIR, $dir or next;
+ while ($_ = readdir DIR) {
+ next if /^\.{1,2}$/;
+ my $path = "$dir/$_";
+ unlink $path if -f $path;
+ recursive_delete($path) if -d $path;
+ }
+ closedir DIR;
+ rmdir $dir or print "error - $!";
+ }
+}
+
+############################################################################
+
+# finds any directories under the arguments, which can be a list of directories.
+sub find_directories {
+ my @dirs_found = ();
+ my $dir;
+ foreach $dir (@_) {
+ local *DIR;
+ # if we can't open the dir, just skip to the next one.
+ opendir DIR, $dir or next;
+ while ($_ = readdir DIR) {
+ # skip if it's current or parent dir.
+ next if /^\.{1,2}$/;
+ my $path = "$dir/$_";
+ # skip if this entry is not itself a directory.
+ next if ! -d $path;
+ push @dirs_found, $path;
+ }
+ closedir DIR;