The problem of changing the order of file names in batch processing

folder contents and file names are shown in the figure. Under each R folder, there is a pile of .jpg files starting with C

R

.

modify directly from R1 to R10 and then return to R2, the picture is the same problem, do not know how to change, hope boss advice!

attach your own bat file

@echo off & setlocal EnableDelayedExpansion
set /a numjpg=0
set /a numfile=0
set ext=.jpg
echo 
for /r . %%i in (*.jpg) do (
    if %%~ni equ C0 (set /a numjpg=0)
    echo  %%i  !numjpg!%ext% >>file.txt
    ren %%i !numjpg!%ext%
    set /a numjpg += 1
)
echo 
for /f "delims=" %%i in ("dir /a:d /b") do (
    if %%~ni equ R0 (set /a numfile=0)
    echo  %%i  !numfile! >>file.txt
    ren %%i !numfile!
    set /a numfile +=1
)
pause>nul
Bat
Mar.23,2021

solve the problem by directly replacing modified characters, so that the sorting problem is not involved

@echo off & color 3a & setlocal enabledelayedexpansion
title ()
echo ()
echo.
set /p str1= ():
set /p str2= ():
echo.
echo 
for /f "delims=" %%a in ('dir /a-d /s /b') do (
if "%%~nxa" neq "%~nx0" (
set "f=%%~na"
set "f=!f:%str1%=%str2%!"
if not exist "%%~dpa!f!%%~xa" ren "%%a" "!f!%%~xa"
)
)
echo 
echo.
echo 
:folder
set n=0
for /f "delims=" %%i in ('dir /ad /s /b ^|find "%str1%"') do (
set t=%%~ni
set t=!t:%str1%=%str2%!
if not exist "%%~dpi!t!" ren "%%i" "!t!" 2>nul
set /a n+=1
)
if "!n!" neq "0" goto folder
echo 
pause
Menu