I have a folder which contains for example the following files:
RAW_123432542_343.text
231453254_213.text
RAW_324324_32432423.text
32432423_4543.text
What I need is renaming all files which do not have RAW_
as prefix. The folder has thousands of files.
How to rename all files within the folder not starting with RAW_
?
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 /?