Search code examples
perlfilenames

Getting a filename using Perl


There is a file named *.iso, where * is any string (dot, numbers, alphabets, spl characters).

*.iso is located at /dm2/www/html/isos/preFCS5.3/

I want to get this filename into $filename. I know it's very simple. How can I do this in Perl?


Solution

  • Use File::Util

    use strict;
    use warnings;
    use File::Util;
    
    my $file_util = File::Util->new;
    my $base = '/dm2/www/html/isos/preFCS5.3/';
    my @isos = $file_util->list_dir(
        $base,
        '--recurse',
        '--files-only',
        '--pattern=\.iso$'
    );