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: 
I finally figured out the **SIMPLEST way** to achieve this by using **BATCH in simplest way.**

By Using following code -

```
del CurDt_5_S*
ren CurDt_4_S* CurDt_5_S*
ren CurDt_3_S* CurDt_4_S*
ren CurDt_2_S* CurDt_3_S*
ren CurDt_1_S* CurDt_2_S*

```

I tested it and its working. :) :) :)
Here is the simplest way I can think of:

```
@echo off
set i=1
for %%f in (CurDt_S*.jpg) do call :renameit "%%f"
goto done

:renameit
ren CurDt_S%i%.jpg CurDt_1_S%i%.jpg

set /A i+=1
:done

```

It assumes the batch files are located in the same directory as the jpg files.

Hope this helps.