Differences

This shows you the differences between two versions of the page.

Link to this comparison view

software:scripts [2011/06/02 16:43]
simon created
software:scripts [2011/09/30 14:45] (current)
simon new scripts
Line 179: Line 179:
 ==== For Each File ==== ==== For Each File ====
  
-|**Description:**|Executes a passed command on every file within a target directory.|+|**Description:**|Executes a passed command on every file within a target directory. |
 |**Language:**|Perl| |**Language:**|Perl|
 |**Example:**|//perl foreachfile.pl c:\scratch *.bmp gzip FILE//| |**Example:**|//perl foreachfile.pl c:\scratch *.bmp gzip FILE//|
Line 188: Line 188:
 my $l_cmd = ""; my $l_cmd = "";
 for (my $i = 2; $i < @ARGV;$i++) { $l_cmd .= " ".$ARGV[$i]; } for (my $i = 2; $i < @ARGV;$i++) { $l_cmd .= " ".$ARGV[$i]; }
-if ($l_dir eq "" or $l_cmd eq "" or $l_cmd !~ /FILE/) { print "What?\n"; exit(1); }+if ($l_dir eq "" or $l_cmd eq "" or $l_cmd !~ /FILE/) 
 +{ 
 +   print "foreach_file <source_dir> <extension> <command>\n"; 
 +   print "\nWhere <command> contains one of more occurence of FILE, which will be replaced by the file being processed.\n"; 
 +   exit(1); 
 +}
 chdir($l_dir); chdir($l_dir);
-foreach (`dir $l_ext /B`)+foreach (`dir $l_ext /B`)  # For Windows 
 +# foreach (`ls $l_ext -1`) # For Linux
 { {
    chomp;    chomp;
 
software/scripts.txt · Last modified: 2011/09/30 14:45 by simon
 
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki