Question: I want to rename a series of .jpg but i want to append the string at the end of file name. Please help me how can I achive this as I am new to batch file coding.

**Series of jpg files** - 
CurDt\_S1, CurDt\_S2, CurDt\_S3 etc.. uptill S20.

**I want to replace CurDt\_S1 with CurDt\_1\_S1 as -** 
CurDt\_1\_S1, CurDt\_1\_S2, CurDt\_1\_S3 uptill S20.

**Here is the code I am using -**

```
setlocal enabledelayedexpansion
    set str=_1
    for %%a in (CurDt_S*.jpg) do (
        set oldName=%%a
        set newName=oldname+str
            call :Action
        echo.
        echo back in For loop
    )
    echo.
    echo For loop completed
    echo !oldName!
    echo !newName!
    endlocal
    goto:eof

    :Action
    echo.
    echo start of Action loop
    echo !oldName!
    echo !newName!
    ren "!oldName!" "!newName!"
    echo end of Action loop

```

Thanks,
Sneha

Answer: 
```
for /L %%x in (1,1,20) do ECHO ren CurDt_S%%x.jpg CurDt_1_S%%x.jpg

```

should work for you.

The required commands are merely `ECHO`ed for testing purposes. After you've verified that the commands are correct, change `ECHO REN` to `REN` to actually rename the files.
```
for %%f in ("c:\somewhere\CurDt_*.jpg") do (
    for /f "tokens=1,* delims=_" %%g in ("%%~nf") do echo ren "%%~ff" "%%~g_1_%%~h%%~xf"
)

```

For each of the indicated files, split the name of the file using the first underscore as delimiter to get the two parts, and rename the file to the the first token + `_1_` + second token + file extension.

Result is only echoed to console. If output is correct, remove `echo` command to rename the files.