Remove "_to" from file name

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
barthez77
Posts: 1
Joined: 18 May 2017 03:41

Remove "_to" from file name

#1 Post by barthez77 » 18 May 2017 03:48

Hi i have this file 2089_24078_to.pdf i need to remove "_to"from name result to be reached 2089_24078.pdf :oops:

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Remove "_to" from file name

#2 Post by aGerman » 18 May 2017 10:20

Assuming there are always two underscores in your file name ...

Code: Select all

@echo off
for %%i in (*_to.pdf) do for /f "tokens=1,2 delims=_" %%j in ("%%~ni") do ren "%%~fi" "%%j_%%k%%~xi"

Steffen

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: Remove "_to" from file name

#3 Post by Compo » 18 May 2017 13:48

…or for every pdf file in "D:\Documents" whose name ends with _to

From the Command prompt:

Code: Select all

For %A In ("D:\Documents\*_to.pdf") Do @Set "_=%~nA"&Call Ren "%A" "%_:~,-3%%~xA"

From a batch file:

Code: Select all

@For %%A In ("D:\Documents\*_to.pdf") Do @Set "_=%%~nA"&Call Ren "%%A" "%%_:~,-3%%%%~xA"

Post Reply