Sheesh, you couldn't make life simpler and say what OS you're using.
Code:
use File::Spec::Functions qw/rel2abs splitpath catfile/;
use strict;
sub mmm_good {
my $d = rel2abs($_[0]);
mkdir $d unless -e $d;
die unless -d $d;
return $d;
}
my(%dirs);
$dirs{c} = mmm_good('source');
$dirs{h} = mmm_good('header');
for my $path (map((glob $_), @ARGV) {
next unless $path =~ /.([chCH])$/ && -r $path;
my $ext = lc $1;
open my $in, "<", $path;
open my $out, ">", catfile($dirs{$ext}, (splitpath($path))[2]);
while(my $line = <$in>) {
$line = lc $line if /^\w*#include/;
print $out $line;
}
close $out;
close $in;
}
Note that this will make two directories in your current working directory. It will overwrite files with the same name. It does not scan subdirectories. It globs (interprets *.* and such) according to csh rules, see perldoc -f glob or perldoc File::Glob. If it runs at all (I haven't tested it) it should run on any OS perl runs on. I think you'll probably need at least perl 5.6 to run this.