# S.Chudley (www.chudley.me) : Executes a passed command on every file within a target directory my $l_dir = $ARGV[0]; my $l_ext = $ARGV[1]; my $l_cmd = ""; for (my $i = 2; $i < @ARGV;$i++) { $l_cmd .= " ".$ARGV[$i]; } if ($l_dir eq "" or $l_cmd eq "" or $l_cmd !~ /FILE/) { print "foreach_file \n"; print "\nWhere contains one of more occurence of FILE, which will be replaced by the file being processed.\n"; exit(1); } chdir($l_dir); foreach (`dir $l_ext /B`) # For Windows # foreach (`ls $l_ext -1`) # For Linux { chomp; my $l_loc_cmd = $l_cmd; $l_loc_cmd =~ s/FILE/$_/g; print `$l_loc_cmd`; }