for x in `ls` ; do ...
but because of the special characters my filenames weren't being read properly. Wonderful!So, after maybe a good 20 minutes of trying to find the right shell commands to use, I gave up and wrote this quick perl script.
So...anybody wanna give me a hint on how I'd be able to do this in a shell script?
#!/bin/perl
#
$dir="/home/drin/tmp/";
opendir(DIR, $dir) || die "Couldn't open $dir";
@files = grep {/.doc/ && -f "$dir/$_"} readdir(DIR);
closedir(DIR);
for $x (@files) {
$y = $x;
$y =~ s/\#//g;
$y =~ s/\ /_/g;
print "Renaming $x to $y\n";
rename ($x, $y);
}
Cheers!
No comments:
Post a Comment