#!/usr/local/bin/perl use vars qw($root_web_path $cur_dir @dirs @unwanted_files); use subs qw(fillUpDirectoryArray performActionOnEachFile GetNextEntry); $root_web_path = "c:/Perl/Perl5.00402/bin"; @unwanted_files = ("Temp(.*)html", "Backup/"); $cur_dir = "0"; @dirs = ($root_web_path); opendir("DIR$cur_dir", $dirs[$cur_dir]); fillUpDirectoryArray(); performActionOnEachFile(); sub fillUpDirectoryArray { my ($end_of_all_files, $filename, $fullpath, $unwanted_file); $end_of_all_files = 0; while (!($end_of_all_files)) { while (1) { $filename = &GetNextEntry("DIR$cur_dir", $dirs[$cur_dir]); $fullpath = "$dirs[$cur_dir]/$filename"; if (!($filename) && $cur_dir > 0) { closedir("DIR$cur_dir"); $cur_dir--; next; } if (!($filename)) { closedir("DIR$cur_dir"); $end_of_all_files = 1; last; } if (-d $fullpath) { if (-r $fullpath && -x $fullpath) { $cur_dir++; $dirs[$cur_dir] = $fullpath; opendir("DIR$cur_dir", $dirs[$cur_dir]); next; } else { next; } } $unwanted_file = 0; foreach (@unwanted_files) { if ($fullpath =~ /$_/) { $unwanted_file = 1; } } if ($unwanted_file) { next; } if (-r $fullpath) { last; } } } } sub performActionOnEachFile { my ($file); foreach $file (@dirs) { print "$file\n"; } } sub GetNextEntry { my ($dirhandle, $directory) = @_; my ($filename); while ($filename = readdir($dirhandle)) { if (($filename =~ /htm.?/i) || (!($filename =~ /^\.\.?$/) && -d "$directory/$filename")) { last; } } $filename; }