Solved Batch remove - and . fixed length many suffix

June 12, 2011 at 19:37:03
Specs: Windows 7
I have to rename thousands of files with the nonstandard characters "." and "-". Fixed length, nothing else in folder, only the number changes, same date & system per folder, can be folder specificic, and multiple suffix, ie:
need to be
or with no spaces instead of "_".

ren 2011-??-?????-??-??.???.test_*.scene.fixed.doc 2011_??_?????_??_??_new_test_*_scene_fixed.doc
ren 2011-??-?????-??-??.???.test_*.scene.fixed.doc 2011_??_?????_??_??_new_test_*_scene_fixed.xls

seems to work, but does not like the number wild card, and only works on one file. I tried a couple for loops, something like

FOR %%*doc IN (C:\Temp) DO (ren "%%*.doc" 2011-??-?????-??-??.???.test_*.scene.fixed.doc 2011_??_?????_??_??_new_test_*_scene_fixed.doc)
but I am sure I have butchered this code.

Any pointers on how to get the number wild card to work or how to get the batch to work? Do you think the FOR loop is appropriate for this? Thanks.

See More: Batch remove - and . fixed length many suffix

Report •

June 13, 2011 at 01:43:31
✔ Best Answer
@echo off & setlocal EnableDelayedExpansion
cd /D Your Folder
for /F %%a in ('dir /B /A-D') do (
  set name=%%~na
  set name=!name:-=_!
  set name=!name:.=_!
  ren %%a !name!%%~xa

Report •

June 13, 2011 at 07:08:12
Thanks IVO,that works great, and the brevity of your solution! You have created a DOS-Batch convert. I'll have to brush up on how to use the filename parameter extensions (ie, %~n, %~a).

Report •

Related Solutions

Ask Question