question

YashiqIrfan-1073 avatar image
0 Votes"
YashiqIrfan-1073 asked SreekanthNadendla-5100 edited

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

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



office-js-dev
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

0 Answers