#!/usr/local/bin/perl # file.pl - routines to help with file management # # Written by Curtis Olson. Started April 22, 1994. # # Copyright (C) 1994 - 1999 Curtis L. Olson - curt@me.umn.edu # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # $Id: file.pl,v 1.1.1.1 1999/12/18 02:04:59 curt Exp $ package CBB; use strict; # don't take no guff # given a directory and an extension mask (: separated list) return a # list of files that match (including all directories) sub get_files { my($dir, $mask) = split(/ +/, $_[0]); my($file, $ext, $count, @files, @sorted); print DEBUG "Directory = $dir\n"; print DEBUG "Mask = $mask\n"; $count = 0; opendir(DIR, $dir); $file = readdir(DIR); # skip "." $file = readdir(DIR); # skip ".." $file = readdir(DIR); while ( defined($file) ) { $ext = &file_extension($file); # print "$file --- $ext\n"; if ( (($mask =~ m/:$ext:/) && ($file ne $ext)) || (-d "$dir/$file") ) { # print "$file\n"; $files[$count] = $file; $count++; } $file = readdir(DIR); } closedir(DIR); @sorted = sort @files; foreach $file (@sorted) { print "$file\n"; } return "//none//"; } 1; # need to return a true value