in reply to How do you list all files under a directory?
Technically a directory is a file, but -f means the subset of files that aren't directories (which excludes '.' and '..'). Be sure to use a full path name in the grep otherwise you will be testing against files in the directory that the program is executing in, which is probably not what you want! When I do want that, I set $dir = "." and use the same formula.
Updated: added single quotes to make '.' and '..' more clear in some fonts.my $dir="/path/to/dir"; opendir(DIR, $dir) or die "can't open $dir: $!"; my @files = grep {-f "$dir/$_"} readdir DIR; closedir DIR;
|
|---|