This could be done for example with following batch code:
@echo off
setlocal EnableExtensions EnableDelayedExpansion
for %%I in ("C:\Temp\*.text") do (
set "FileName=%%~nI"
if /I not "!FileName:~0,4!" == "RAW_" ren "%%~I" "RAW_%%~nxI"
)
endlocal
If a string is assigned to an environment variable within a code block starting with (
and ending with a matching )
and referencing the string or parts of the string of this environment variable within same code block is necessary as for this rename operation, delayed expansion must be used as shown above. The help of command set
explains this on a simple IF and a simple FOR example very clear.
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
echo /?
endlocal /?
for /?
if /?
ren /?
set /?
setlocal /?