+ }
+
+ local *DIR;
+ opendir DIR, $dir or die "opendir $dir: $!";
+ 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 (@_) {
+printf "FD outer dir: $dir\n";
+ local *DIR;
+ opendir DIR, $dir or die "opendir $dir: $!";
+ 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;
+printf "FD adding $path to our list.\n";
+ push @dirs_found, $path;
+ }
+ closedir DIR;
+ }
+ return @dirs_found;
+}
+
+############################################################################
+
+# given a directory, this returns an array of all the filenames found therein.
+sub find_files {
+ my @files_found = ();
+ my $dir;
+ foreach $dir (@_) {
+#printf "LFN outer dir: $dir\n";
+ local *DIR;
+ opendir DIR, $dir or die "opendir $dir: $!";
+ while ($_ = readdir DIR) {
+ # skip if it's current or parent dir.
+ next if /^\.{1,2}$/;
+ my $path = "$dir/$_";
+ # skip if this entry is not a file.
+ next if ! -f $path;
+#printf "LFN adding $path to our list.\n";
+ push @files_found, $path;
+ }
+ closedir DIR;