Skip to main content
2 of 2
added 45 characters in body
user avatar
user avatar

The perl-way:

#!/usr/bin/perl

opendir(DIR,".") or die "$@:$!";
while ($in = readdir(DIR)) {
  next unless -f $in;
  ($out = $in) =~ s/[^a-zA-Z0-9._-]//g;
  warn "$@:$!" unless rename $in, $out;
}
closedir(DIR);

The regex filters only a-zA-Z ... (could also be [:print:] for printable chars) as valid chars. There is no checking for empty target names.

user55518