Click to See Complete Forum and Search --> : file name formatting


bkelly
06-20-2007, 08:11 PM
After copying numerous pictures from my camers to hard drive, I gave them descriptive names. Now that I want to upload some of them to my web page, I discover that my site host cannot tolerate spaces in file names.

Does anyone know of a utility that will rename files to remove spaces in the name? I prefer to replace the spaces with underscore characters but will take what I can get.

Thank you,
bkelly

ray326
06-20-2007, 10:34 PM
Google is your friend.

http://www.google.com/search?q=remove+spaces+from+file+names

I think I'd try this one first if you're on Windows.

http://www.snapfiles.com/Freeware/system/fwfilerename.html

aaronuni
06-29-2007, 12:42 PM
Do you have perl installed on your server? If so try this script:


#!/usr/bin/perl -w

use File::Find;
use strict;
die "usage: nospace dir[s]\n" unless @ARGV;

my %ext;

find(\&remspaces, @ARGV);

sub remspaces {
return if ($_ eq '.');
return if ($_ eq '..');
(my $new = $_) =~ tr/a-zA-Z0-9_.-/_/c;
my $duplicate = ($new ne $_ and -e $new);
my $try = $new;

$ext{"$File::Find::dir/$try"}++ if $duplicate;

while (my $count = $ext{"$File::Find::dir/$new"}++) {
(my $with_num = $new) =~ s/(?=\.|$)/_$count/;
$new = $with_num, last if not -e $with_num;
}

$ext{"$File::Find::dir/$try"}-- if $duplicate;

rename $_ => $new
or warn "can't rename $_ to $new: $!";
}


Copy above into a new file, save it as nospace.pl, make it executable and run it by giving it a directory to work on. Thus if your files were in a directory called pics call it with:

./nospace.pl pics

Hope it helps...

bkelly
07-04-2007, 06:56 PM
I don't have Perl but I did download Bulk Rename Utility. That has a bunch of options and the instructions are not at all clear. However, I was able to set a field to change the extension to lower case and it did the trick.

That is all I really needed from this guy. Thanks for the tip.

bkelly