I have file name like 114721_1731681_GHYTRH_Rebook_Linz_HYTRFHJ_3427238_052113.txt . I want to rename the file by retaining the values from left till second underscore like _3427238_052113.txt
Can any one have a quick solution?
Rename a file
Moderator: DosItHelp
Re: Rename a file
what you show is the 6th underscore from left. <----there is the left side, on the beginning.
Code: Select all
@echo off&setlocal
set "name=114721_1731681_GHYTRH_Rebook_Linz_HYTRFHJ_3427238_052113"
for /f "tokens=1-6*delims=_" %%a in ("%name%") do set "newname=%%a_%%b_%%c_%%d_%%e_%%f"
echo ren "%name%" "%newname%"