Solved rename a group of files

Dell Poweredge t310 tower server - custo...
August 25, 2013 at 00:13:25
Specs: Windows Server 2003, Xeon
I need to rename a group of files in the same folder. When I try to run the batch file, it doesn't work correctly:

`ren *.txt Updated_*.txt`

The file names contain date_names_location.txt, examples are below

08232013_name1_nyc.txt
08212013_name1_nyc.txt
08232013_name1_la.txt
08212013_name1_la.txt

When I run the batch file I get back:
Updated_1_name1_nyc.txt
instead of 'Updated_08232013_name1_nyc.txt'

Any ideas on how to fix? Thanks


See More: rename a group of files

Report •


#1
August 25, 2013 at 04:07:52
✔ Best Answer
::====== script starts here ===============
::
:: forefj.bat 2013-08-25 17:56:44.10
@echo off > NEWFILE & setLocal enableDELAYedeXpansioN

for /f "tokens=* delims= " %%i in ('dir/b *.txt') do (
ren %%i Updated_%%i
)
::====== script ends here =================

=====================
M2 Golden-Triangle


Report •

#2
August 25, 2013 at 18:52:53
I recall this same problem from a year or two ago, involving wildcard rename/copy/move, and the issue was that the new data is NOT INSERTED into the original filename, but OVERWRITES it for the duration of the new-data length, then whatever is left of original filename is appended to that. I don't think there's a way to override that, so M2's solution is your answer.

Report •

#3
August 25, 2013 at 19:26:48
Mechanix2Go your solution worked perfectly, thanks so much!

Report •

Related Solutions


Ask Question