Hi,
i have some files in a folder. I need to create a .bat file which will rename all the files to different name. The files name will be in a format like "xxx20100918xxx.doc" and I need to rename it to 20100918.doc.
is it possible to do it in batch?Any suggestions
Thanks,
Skunkhead
how to rename files name using batch?
Moderator: DosItHelp
Re: how to rename files name using batch?
Code: Select all
@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%f in ('dir /b ??????????????.doc') do (
set "name=%%~nf"
ren "%%f" "!name:~3,8!%%~xf"
)
Last edited by !k on 03 Mar 2011 11:55, edited 1 time in total.
Re: how to rename files name using batch?
!k is right in case the file name has always 14 characters and the date starts after the 3rd. Otherwise you should define a rule how to extract the date and tell us what these triple x's are for.
Regards
aGerman
Regards
aGerman
Re: how to rename files name using batch?
ver.2
Code: Select all
@echo off
setlocal enabledelayedexpansion
set "year=2010"
for /f "delims=" %%f in ('dir /b *%year%*.doc ^|^
findstr /rc:".*[^0-9]%year%[0-9][0-9][0-9][0-9][^0-9].*"'
) do (
set "name=%%~nf" &set "newname="
for /l %%c in (0,1,255) do (
set "char=!name:~%%c,1!"
if "!char!" GEQ "0" if "!char!" LEQ "9" set "newname=!newname!!char!"
)
ren "%%f" "!newname!%%~xf"
)