-1

I have a folder that has a bunch of files such image_hello.png, helloworld.png, wired.png. I would like to copy these files and then rename them as 1.png, 2.png, 3.png via script or batch file

I am not sure what the best way to start this is, i can copy over the files easily, but after that, i am not sure how to rename them based on the extension.

Any ideas?

samsam
  • 27
  • 6

2 Answers2

0

Something like this:

@echo off
SET count=1
FOR /f "tokens=*" %%G IN ('dir /b *.png') DO (call :rename_next "%%G")
GOTO :eof

:rename_next
ren "%1" %count%.png
set /a count+=1
GOTO :eof
Dean Taylor
  • 40,514
  • 3
  • 31
  • 50
0

Take a look here:

Something along these lines should work (note: don't have Windows to test):

set n=1
for %%i in (*.png) do (
  call ren %%i %%n%%.pn_
  set /a n=n+1)
ren *.pn_ *.png

Note that if you only want to do it once, you can use Explorer, as per here:

or some other utilities, like the one mentioned in the first link:

icyrock.com
  • 27,952
  • 4
  • 66
  • 85