in reply to Re: File types not being picked up by script
in thread File types not being picked up by script

Hi, by pick up I mean to say that, the code finds all of the directories and files correctly, except the ones I listed that it does not.

I dont have the join(':',stat $_) in my code.

As per your comment, I have added the code below on how I set the @files

```
my @files; my $path = shift; opendir (DIR, $path) or die "Unable to open $path: $!"; my @files = # Third: Prepend the full path map { $path . '\\' . $_ } # Second: take out '.' and '..' grep { !/^\.{1,2}$/ } # First: get all files readdir (DIR); closedir (DIR);
```

Replies are listed 'Best First'.
Re^3: File types not being picked up by script
by Marshall (Canon) on Jul 07, 2025 at 07:21 UTC
    I am not sure exactly what you are trying to do but as has been mentioned File::Find is the right tool for this job. This is some untested code for your pleasure...
    use strict; use warnings; use File::Find; my $starting_dir = "put path to dir here"; my $count_dat_png = 0; find(\&wanted, $starting_dir); print "number of dat and png files: $count_dat_png\n"; sub wanted { return if -d ; # skip directories # . and .. are directories # or just leave this out entirely if (-f and ( /\.dat$/i or /\.png$/i)) { #print "$File::Find::name\n"; #full name if you want $count_dat_png++; } }
    added: I would read the example and explanation of the module File::Find carefully.

      Thank you both for your feedback, greatly appreciated. I will try your suggestions.