Aug 19, 2004 #1 naq2 Programmer Joined Aug 3, 2004 Messages 74 Location FR How can I list the files and perform an action on eachone. An algorism of what I want to do could be: Code: foreach FILE in DIRECTORY { PERFORM AN ACTION ON THE FILE } Thanks in advance.
How can I list the files and perform an action on eachone. An algorism of what I want to do could be: Code: foreach FILE in DIRECTORY { PERFORM AN ACTION ON THE FILE } Thanks in advance.
Aug 19, 2004 1 #2 toolkit Programmer Joined Aug 5, 2001 Messages 771 Location GB Lots of different ways: Code: opendir(DIR, "."); foreach (readdir(DIR)) { next unless -f; print "do something with $_\n"; } closedir(DIR); Or: Code: opendir(DIR, "."); @files = grep {-f} readdir(DIR); closedir(DIR); foreach (@files) { print "do something with $_\n"; } Or if you want to recurse down into subdirectories: Code: use File::Find; sub wanted { if (-f) { print "do something with $File::Find::name\n"; } } find(\&wanted, "."); Cheers, Neil Upvote 0 Downvote
Lots of different ways: Code: opendir(DIR, "."); foreach (readdir(DIR)) { next unless -f; print "do something with $_\n"; } closedir(DIR); Or: Code: opendir(DIR, "."); @files = grep {-f} readdir(DIR); closedir(DIR); foreach (@files) { print "do something with $_\n"; } Or if you want to recurse down into subdirectories: Code: use File::Find; sub wanted { if (-f) { print "do something with $File::Find::name\n"; } } find(\&wanted, "."); Cheers, Neil
Aug 19, 2004 Thread starter #3 naq2 Programmer Joined Aug 3, 2004 Messages 74 Location FR Whao! this is great! Thanks. Upvote 0 Downvote