I have a bunch of files named YYYYDDMM_prep888 and I want to rename them to YYYYMMDD_prep888, just exchanging DD for MM. I'd appreciate some help. Thanks.
Assuming that your files have a regular form you can use a similar batch file:
@echo off setlocal enableextensions enabledelayedexpansion FOR /F %%A IN ('dir /b *_prep888') DO ( rem split the data set file=%%A set pre=!file:~0,4! set dd=!file:~4,2! set mm=!file:~6,2! set post=!file:~8,8! set new_name=!pre!!mm!!dd!!post! ECHO renaming !file! into !new_name! ren !file! !new_name! )