This is a bit of a hack, but it works.
to use it, copy the code below to a file on your server ie. space_eater.pl
Edit the $start_folder line to reflect the correct directory on your server.
Then chmod the file 755
from a command line type
CODE
perl ./space_eater.pl
( when you are in the scripts directory )
CODE
#!/usr/bin/perl
use Shell qw(ls mv);
################################################################
$start_folder = "/path/to/directory/containing/filenames/with/spaces"; ### < < < edit this line ###
################################################################
$fillgap = "_"; ### this is the replacement character
$count=0; ### zero the counter
chdir $start_folder; ### like it says ...
opendir This, ".";
@isafile = ls; ### collect the filenames for processing
closedir This;
if ($#isafile > "0") { ### if the listing found any files then ...
for $element (@isafile) {
chomp $element; ### get rid of newline chars
chomp $element;
$nospace = $element; ### reassign the filename for processing
$element =~ s/ /*/; ### substitute the space in the name for a wildcard
### so that the mv command works correctly
$nospace =~ s/ /$fillgap/; ### This section substitutes a space in the filename
$nospace =~ s/ /$fillgap/; ### for a _ (underscore)
$nospace =~ s/ /$fillgap/; ### done 3 times coz it only does one space per pass
### and there may be more than one space
mv ($element, $nospace); ### rename the file
print "$element renamed to $nospacen"; ### report to the user
$count +=1; ### increment counter
}
}else{
print "No files present";
exit;
}
print "$count filenames have had spaces replaced by underscores. n";
print "Goodbye n";
exit;
alan
[edit] Yeah, I know perldork can do much better, if fact I'd like to compare his solution to mine so I can learn ;-)
First things I can see wrong, are
1) no checks to see if the filename
needs processing
2) if ($#isafile > "0"){ } should be if @isafile{ } so as to catch a lone file
3) s// should be in a loop dynamically limited by number of spaces found in each name
4) I should have used strict and perl -w
5) Any others ?
[/edit]