Remove the trailing from filename

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
zagix
Posts: 68
Joined: 16 Oct 2013 23:19

Remove the trailing from filename

#1 Post by zagix » 19 Nov 2013 14:02

Hello,

I have multiple xml file in folder, which are response files received after processing them from our central office.

File name: Exec_19112013_1.XML.1.19112013.PASS

To remove the trailing .1.19112013.PASS after .XML

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Remove the trailing from filename

#2 Post by Squashman » 19 Nov 2013 14:33

And what happens if more than one file has Exec_19112013_1.XML as the beginning of the file name?
Regardless of that this would work if that will never happen.

Code: Select all

@echo off
for %%G in (*.XML.*) do (
   for /f "tokens=1,2 delims=." %%I in ("%%~G") do echo rename "%%~G" "%%~I.%%~J"
)

zagix
Posts: 68
Joined: 16 Oct 2013 23:19

Re: Remove the trailing from filename

#3 Post by zagix » 19 Nov 2013 14:36

Squashman wrote:And what happens if more than one file has Exec_19112013_1.XML as the beginning of the file name?


The files are in sequential order. i.e. Exec_19112013_2.XML, xxx.3.XML

Thanks

zagix
Posts: 68
Joined: 16 Oct 2013 23:19

Re: Remove the trailing from filename

#4 Post by zagix » 19 Nov 2013 14:52

Code: Select all

@echo off
for %%G in (*.XML.*) do (
   for /f "tokens=1,2 delims=." %%I in ("%%~G") do echo rename "%%~G" "%%~I.%%~J"
)


Sorry, this does not remove the trailings from the file name.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Remove the trailing from filename

#5 Post by Squashman » 19 Nov 2013 15:00

Which means you don't know how the code works.
Remove the echo command in front of the rename command.
Most of us will put the echo in the code as a precautionary measure so you can see how it will be renamed before you actually want to rename them.

zagix
Posts: 68
Joined: 16 Oct 2013 23:19

Re: Remove the trailing from filename

#6 Post by zagix » 19 Nov 2013 21:41

Hi,

Thanks Squashman.
Fantastic.

Post Reply