How to see if there is a * .png file in the directory?

    1 answer 1

    For example, -X A file test, where X is one of the letters listed below ... :

    if( -f '/path/file.png' ) { # файл есть } else { # файла нет } 

    But in general it all depends on the goals. You can try to open, if you still need to do it anyway.


    If you need to check the existence of any file by mask, you can use the glob function:

     my @files = glob '/path/*.png'; if( @files ) { # какие-то файлы есть (Но не факт, что файлы, # под маску могут попасть и каталоги!) } else { # файлов нет } 

    If you get a list of files by mask - the same glob or (with dropping directories):

     opendir my $dir, '/path/'; my @files = grep { -f "/path/$_" && /.*[.]png$/ } readdir $dir; closedir $dir;