I have 100 .png files in a folder say test.png, example.png, etc.
I want to prepend them with
New_ so that it will be renamed as
How can I do it in shell.
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 didn't specify an operating system. This answer assumes Windows.
My first thought was a simple command such as
for %f in (*.png) do rename "%f" "New_%f"
But a file named
a.png was first renamed to
New_a.png and moved down the alphabetical order :-( The loop renamed this file a second time to New_New_a.png.
Therefore, this must be done in two steps:
dir /b *.png > png.txt for /F %l in (png.txt) do rename "%l" "New_%l" del png.txt
The first line creates a text file containing the names of all png files in the current directory. The second line parses each line of the file and renames the png's.