Rename a file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
awaneesh.pandey
Posts: 1
Joined: 23 May 2013 07:44

Rename a file

#1 Post by awaneesh.pandey » 23 May 2013 07:54

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?

Endoro
Posts: 244
Joined: 27 Mar 2013 01:29
Location: Bozen

Re: Rename a file

#2 Post by Endoro » 23 May 2013 07:58

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%"

Post Reply