Below code process each files in the /tmp directory. If any directory is inside the /tmp directory will not be processed
Add additional checking on file, like file size and readable permissions to avoid error.
#!/usr/bin/perl use strict; use warnings; my $tmp_dir="/tmp/"; opendir (DIR, $tmp_dir) or die $!; while (my $file_name = readdir(DIR)) { my $abs_path = $tmp_dir.$file_name; unless(-d $abs_path) #Ignore if it is a directory { &Process_EachFile($abs_path); # Do call a function and process + each file } else { print "$abs_path is a directory\n"; } } closedir(DIR); sub Process_EachFile { my ($filename) = @_; print $filename; open (FH,'<',"$filename") or die $!; while(my $each_line=<FH>) { print $each_line."\n"; #Read file content here and do your calculation. } }
In reply to Re^3: Open a folder
by vinoth.ree
in thread Open a folder
by Dr Manhattan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |