in reply to Why is "If" condition not working
There is a module File::Find which is handy for doing recursive searches of a directory tree. See File::Find. File::Find starts at the directory that you specify and for every directory and file found, it calls a subroutine that you specify. Below this is just called "wanted". There are some special variable names that apply while you are inside the wanted subroutine as shown below.
#!/usr/bin/perl -w use strict; use File::Find; # within the wanted subroutine: # # http://perldoc.perl.org/File/Find.html # $File::Find::dir is the current directory name, # $_ is the current filename within that directory # $File::Find::name is the complete pathname to the file. my @directories_to_search = ('C:/temp'); find(\&wanted, @directories_to_search); sub wanted { print "$File::Find::name\n" if -f; }
|
|---|