How to append a symbol before last 6 digit of a file name in batch script

Yashiq Irfan 1 Reputation point
2021-09-06T05:08:29.65+00:00

I am creating a Batch script for following tasks:

Task 1: Find a specific name (.txt.) and replace with specific name(.txt_) in all the file name in a folder.

Task 2: Append a symbol(_) before last 6 digit of a file name in batch script.

As Is: Test.txt.20210808654321

To be: Test.txt_20210808_654321

I have created a script for Task 1 and it is working.

Script:

@echo off
setlocal enabledelayedexpansion

set "replace=.txt_"
set "find=.txt."

for %%i in ("C:\Script test\*.*") do (
   set name=%%~ni
   set ext=%%~xi
   ren "%%i" "!name:%find%=%replace%!!ext!"
)
pause

I am struck in Task 2 (= Append a symbol(_) before last 6 digit of a file name).

Please help

JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
882 questions
0 comments No comments
{count} votes