Adding a new prefix to multiple files - any easy way?
Adding a new prefix to multiple files - any easy way?
Author
Discussion

FourWheelDrift

Original Poster:

92,382 posts

315 months

Saturday 24th February 2007
quotequote all
If I had 100+ files I need to rename but keep their naming structure and current names, but just add a new prefix to each one.

e,g change

image41.gmt
cube_map.jpg
body1.dds

by adding 138_ to the front into

138_image41.gmt
138_cube_map.jpg
138_cube_map.jpg

It a batch conversion app I'm after than can rename many different files just by adding a standard prefix and not changing any other part of the naming.


Any recommendations or know of anything to do this?

eyebeebe

3,870 posts

264 months

Saturday 24th February 2007
quotequote all
I have just the piece of software for you. I don't have permission to send email from here apparently. If you send me an email I'll send the file back by return. It's only 300k or so

FourWheelDrift

Original Poster:

92,382 posts

315 months

Saturday 24th February 2007
quotequote all
PH email is busted for me as well but you can try

Many thanks. Appreciate it (well my fingers certainly do)


Edited by FourWheelDrift on Saturday 24th February 21:41

eyebeebe

3,870 posts

264 months

Saturday 24th February 2007
quotequote all
YHM

-DeaDLocK-

3,368 posts

282 months

Saturday 24th February 2007
quotequote all
I've used File Renamer hundreds of times for jobs like this - freeware, and a very well designed piece of software.

Download link: www.sherrodcomputers.com/downloads%5CFileRenamerBasic.exe

FourWheelDrift

Original Poster:

92,382 posts

315 months

Saturday 24th February 2007
quotequote all
eyebeebe said:
YHM


I haven't yet




I'll have a go at the link above as well though

zumbruk

7,848 posts

291 months

Saturday 24th February 2007
quotequote all
The perl "rename" program. Don't leave home without it;

($op = shift) || die "Usage: rename perlexpr [filenames] ";
if (!@ARGV) {
@ARGV = <STDIN>;
chop(@ARGV);
}
for (@ARGV) {
$was = $_;
eval $op;
die $@ if $@;
rename($was,$_) unless $was eq $_;
}

In your case it would be called as;

rename 's/^/138_/;' *

eyebeebe

3,870 posts

264 months

Saturday 24th February 2007
quotequote all
FourWheelDrift said:
eyebeebe said:
YHM


I haven't yet




I'll have a go at the link above as well though


how bizarre. I sent it straightaway from a hotmail account. Maybe it is in your junk folder? The program is called Batch File Renamer if you want to google it. Filename BatchFR.exe

FourWheelDrift

Original Poster:

92,382 posts

315 months

Saturday 24th February 2007
quotequote all
Nope, nothing.



Edited by FourWheelDrift on Saturday 24th February 21:42

eyebeebe

3,870 posts

264 months

Saturday 24th February 2007
quotequote all
nope sent it as that. It's probably hotmail arseing about!

This is a link to it anyway

http://cerebralsynergy.com/download.p

FourWheelDrift

Original Poster:

92,382 posts

315 months

Saturday 24th February 2007
quotequote all
Thanks.

GreenV8S

31,027 posts

315 months

Saturday 24th February 2007
quotequote all
If you're running a recent version of Windows you can do that using the DOS shell extensions if you don't mind typing the command in. It will be something along the lines of:

for %f in ( <my list of files> ) do rename %f foo_%f

Replace <my list of files> with a wildcard expression that selects the files you want to rename, *.mpg etc.

Size Nine Elm

5,167 posts

315 months

Saturday 24th February 2007
quotequote all
GreenV8S said:
If you're running a recent version of Windows you can do that using the DOS shell extensions if you don't mind typing the command in. It will be something along the lines of:

for %f in ( <my list of files> ) do rename %f foo_%f

Replace <my list of files> with a wildcard expression that selects the files you want to rename, *.mpg etc.

I was going to suggest that - only the Unix equivalent... best use of cygwin on Windows.

FourWheelDrift

Original Poster:

92,382 posts

315 months

Saturday 24th February 2007
quotequote all
Thanks, done now

Church of Noise

1,657 posts

268 months

Sunday 25th February 2007
quotequote all
The simple way of doing it: put the files in a separate directory, go into command prompt and type
rename *.* 138_*.*

BliarOut

72,863 posts

270 months

Sunday 25th February 2007
quotequote all
Church of Noise said:
The simple way of doing it: put the files in a separate directory, go into command prompt and type
rename *.* 138_*.*


yes
Although

ren *.* 138_*.*
saves you typing three characters

eyebeebe

3,870 posts

264 months

Sunday 25th February 2007
quotequote all
BliarOut said:
Church of Noise said:
The simple way of doing it: put the files in a separate directory, go into command prompt and type
rename *.* 138_*.*


yes
Although

ren *.* 138_*.*
saves you typing three characters

I was going to suggest that but did I test first and whenever I did it, it added an additional '.' between the prefix and the original name, hence I didn't recommend that option.

Mr E

23,096 posts

290 months

Sunday 25th February 2007
quotequote all
with a real OS (*nix), and assuming you want to rename all the files the CWD, I think I can do it in a line.

find . -name * -exec mv {} 138_{};

I think will do what you want. Bear in mind that this is off the top of my head and I've not tested it.

GreenV8S

31,027 posts

315 months

Sunday 25th February 2007
quotequote all
You might want to limit that to files ...

BliarOut

72,863 posts

270 months

Sunday 25th February 2007
quotequote all
eyebeebe said:
BliarOut said:
Church of Noise said:
The simple way of doing it: put the files in a separate directory, go into command prompt and type
rename *.* 138_*.*


yes
Although

ren *.* 138_*.*
saves you typing three characters

I was going to suggest that but did I test first and whenever I did it, it added an additional '.' between the prefix and the original name, hence I didn't recommend that option.

That's odd.... In theory there shouldn't be any difference. Ah well, such is 'Doze