radical hacks WebBBS File Attachment Enhancements sent in the following awesome addition to the archive.....

"Hello,

I was checking out the Hacks page when I came across the particularly lengthy and complicated directory parsing script. It seemed like a expensive way to go just to get a list of files, so I thought I would clean it up a bit, and then decided to just start from the begining.

    #!perl

    $osd = ':';
    @directories  = ('path:to:dir:');
    @file_ext_not = ('pl', 'cgi');
    @dir_not      = ('do:not:search:me:',
                 'do:not:search:me:either:',);

    foreach $dn (@dir_not)      { $dn{$dn} = 1; }
    foreach $fn (@file_ext_not) { $fn{$fn} = 1; }

    foreach $dir (@directories)
        {
            # start at the top, no counters
            # avoiding the extra foreach within our loop
        if (!($dn{$dir}))
            {
            # collect up the stuff that readdir will eat
            @this_dir_root = split (/$osd/, $dir);
            $junk = pop @this_dir_root;
            $this_dir_root = join ("$osd", @this_dir_root);

            opendir THEDIR, "$dir";
            @infiles = grep !/^\./, readdir THEDIR;
            foreach $infile (@infiles)
                {
                $possible_dir = "$dir$infile$osd";
                $infile = "$dir$infile";
                # just add it to what we're looping through already
                # avoiding the jumping around with next or last
                if (-d $possible_dir) { push (@directories, "$possible_dir"); 
                }
            else
                {
                ($junk, $ext) = split (/\./, $infile);
                if ((!($fn{$ext})) && (-T $infile))
                    {
                    push (@files, $infile); # or whatever...
                    }
                }
            }
        close THEDIR;
        }
    }

    print (join ("\n", @files));
    print "\n--\n";
    print (join ("\n", @directories));
    print "\n--\n";
    @clock = times;
    print "run time = $clock[0]\n\n";

    exit;