Search file type Only (Perl - Win32)

Discussion in 'Scripts' started by sf500, Oct 16, 2009.

  1. #1
    Hello everyone,
    I have a directory structure that has many other directories that contains a variety of file types.
    With that in mind, I would like to search all "@filetypes = ();" throghtout the entire "$path = 'C:\structure';" stucture and insert it into a "$found_ftype = 'found_file_types.txt';" file.

    HERE IS THE CODE:
    #!C:\Perl\bin\perl -w
    use File::Basename;
    sub recurse($) {
    my($path) = @_;
    $path .= '/' if($path !~ /\/$/);
    for my $eachFile (glob($path.'*')) {
    if( -d $eachFile) {
    recurse($eachFile);
    } else {
    my(undef, undef, $ftype) = fileparse($eachFile,qr"\.[^.]*");
    $filetypes[$i++] = toLower($ftype);
    }
    }
    }

    sub toLower($) {
    local($string) = $_[0];
    $string =~ tr/A-Z/a-z/;
    $string;
    }
    our @filetypes = ("");
    our $i = 0;
    recurse($ARGV[0]);
    undef %saw;
    @out = sort grep(!$saw{$_}++, @filetypes);
    print "@out\n";
     
    sf500, Oct 16, 2009 IP