Adding a prefix to file names in Windows.

December 1, 2010 at 02:47:42
Specs: Windows XP
Can anyone please help me with a script for Adding a prefix to file names in Windows.

e.g. in a directory a have files abcd.txt, efgh.txt
I want the file names to look like : in_abcd.txt, in_efgh.txt
(Prefixing "in_" in the beginning of the file.)

I also have some file with the name : in_1234.txt
So i do not want to rename the files which already have "in_" prefixed in front of the file name.

Any help is highly appreciated

Thanks in advance.
Joy


See More: Adding a prefix to file names in Windows.

Report •

#1
December 1, 2010 at 04:20:11
@echo off & setLocal EnableDELAYedeXpansion

for /f "tokens=* delims= " %%a in ('dir/b') do (
set F=%%a
if !F:~0^,3! neq IN_ ren %%a IN_%%a
)


=====================================
Life is too important to be taken seriously.

M2


Report •

#2
December 1, 2010 at 04:41:58
Thank You for your help.

I also have some files with the name : IN_1234.txt
So i do not want to rename the files which already have "IN_" prefixed in front of the file name.

The script works fine, but it also renames the files which have "IN_" already prefixed with it.
So i now have a file "IN_IN_1234.txt".

Can you please help me sort this out.

Thanks,
Joy


Report •

#3
December 1, 2010 at 04:54:06
It didn't for me.


=====================================
Life is too important to be taken seriously.

M2


Report •

Related Solutions

#4
December 1, 2010 at 08:40:05
This worked. Thanks for that.

Well i was also trying for a prefix of "IND_" and this was prefixing it to all files (even to files which already have IND_ prefixed to it).

Have now changed the code from :" if !F:~0^,3! neq IN_ ren %%a IN_%%a "
to :" if !F:~0^,4! neq IND_ ren %%a IND_%%a "

and now it works fine.

Thanks a ton.

Cheers,
Joy


Report •

Ask Question