MakkaCha
MakkaCha

Reputation: 35

Strip date from filename using batch script

I have multiple files with dates on them I would like to strip.

exOpTimer01232018.txt

exOpProcess01232018.txt

exOpFac01232018.txt

exOpProd01232018.txt

I would like to have a batch script remove the date and leave result such as

exOpTimer.txt

exOpProcess.txt

exOpFac.txt

exOpProd.txt

These are monthly file and the date stamp changes every month.

I have tried doing

RENAME C:\temp\*????????.txt *.txt

But wasn't successful.

Upvotes: 1

Views: 1236

Answers (1)

Compo
Compo

Reputation: 38579

Example based on my comment:

@Echo Off
For /F "Delims=" %%A In ('Where .:exOp*.txt 2^>Nul') Do Call :Loop "%%A"
Pause
Exit

:Loop
Set "fName=%~n1"
Ren %1 "%fName:~,-8%%~x1"

Upvotes: 2

Related Questions