Hello everyone,
I want to rename files but in doing so, i want to be able to replace matching text with another.
So only the text specified gets changed. I wish to do it in batch, more than one file at a time.
Currently i have the following (hope i outline it clear enough)
The file names i wish to to change are:
A3-12345_iuiu.TXT
A3-12365_opop.TXT
The desired result i want is
A1 - 12345_iuiu.TXT
A1 - 12365_opop.TXT
The code i have so far, it does kind of what i want, it replaces the A3 with A1 and puts the spaces but i want to replace the "A3-" with "A1 - "
REN D:\Program Files\A3-*.TXT "A1 - *.TXT"
The result i get is:
A1 - 345_iuiu.TXT
A1 - 365_opop.TXT
It removes the first 2 charactoers of the numbers, this is because it does a straight rename (replacing the 3 charcaters i specifed with the 5 new characters), is there are way to replace 3 characters with 5 and not lose any of the text?
Thanks in advance,
jac
Batch rename- string replace in file name
Moderator: DosItHelp
Re: Batch rename- string replace in file name
You will have to parse and build the names yourself.
Try this (double %% assumes batch file)
The code may have to change significantly if the name and/or path patterns change.
Dave Benham
Try this (double %% assumes batch file)
Code: Select all
for /f "tokens=1,* delims=-" %%A in ('dir /b "D:\Program Files\A3-*.TXT"') do ren "D:\Program Files\A3-%%B" "A1 - %%B"
The code may have to change significantly if the name and/or path patterns change.
Dave Benham