I have a folder with images :
1.png 2.png 3.png ... 11000.png.
And I want to rename this files adding a p- as follows:
p-1.png p-2.png ... p-11000.png
How can I achieve this? I tried
ren *.png ???-p.*
but this is giving the opposite results.
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
You can use a for loop to iterate each file in a directory and use variable substitutions to get the specific name portion of each file. You can use those and add in the "
p-" string and append it as a prefix with the
ren command for each file getting the expected output result you desire.
Essentially this. . .
for %a in ("C:\path\*.*") do if [%~xa]==[.png] ren "%~a" "p-%~Na%~Xa"
SET "Src=C:\path" SET "Str=p-" for %%a in ("%Src%\*.*") do if [%%~xa]==[.png] ren "%%~a" "%Str%%%~Na%%~Xa"
Variable Substitutions (FOR /?)
In addition, substitution of FOR variable references has been enhanced. You can now use the following optional syntax:
%~I - expands %I removing any surrounding quotes (") %~nI - expands %I to a file name only %~xI - expands %I to a file extension only