0

I have a folder full of PNG files:

Image1.png
Image2.png
Image3.png
...
Image47.png

I want to rename them like this (same order):

0.png
1.png
2.png
...
46.png

Ty for your help!

Foxxey
  • 15
  • 4
  • 1
    Your question is an off topic code request. As you're new here, I advise that you take the [tour], and read all of [ask], and its linked pages, before submitting questions, you shouldn't. – Compo Jan 23 '21 at 09:02
  • I would advise that you take a look at this [powershell question](https://stackoverflow.com/q/5427506), and answers, if you were hoping to sort according to Windows Explorer's order. – Compo Jan 23 '21 at 09:23

2 Answers2

0

You can use this in the same folder. It will remove the text "Image" for each .png filename.

@echo off
Setlocal enabledelayedexpansion

Set "Pattern=Image"
Set "Replace="

For %%# in ("*.png") Do (
    Set "File=%%~nx#"
    Ren "%%#" "!File:%Pattern%=%Replace%!"
)

Pause&Exit
Timothy Alexis Vass
  • 2,526
  • 2
  • 11
  • 30
  • The OP doesn't want to remove the prefix from their files, they wish to rename them numerically from `0`, in increments of `1`, without changing their perceived 'order' – Compo Jan 23 '21 at 09:14
  • The question has changed since I answered it. ;) – Timothy Alexis Vass Jan 24 '21 at 07:57
  • It has, you are correct! However, the question has not fundementally changed. At the time you posted your answer, the question read, "I have a folder full of PNG-Files: Image1.png, Image2.png, Image4.png, ..., Image47.png. I want to rename them like this (same order): 0.png, 1.png, 2.png, ... 46.png.". _(Prior to that content the initial post was the same except for `Image47.png` reading `Image48.png` and `46.png` reading `47.png`, which does not affect the intent)_. It is clear from the `0` becoming `1`, that the intention was not to just remove `Image`, but to renumber from an index of `0`. – Compo Jan 24 '21 at 14:40
0
for /f "tokens=1*delims=:" %%b in ('dir /on /b /a-d image*.png 2^|findstr /n ".*" ') do ren "%%b" "%%a.png"

As a batch line should do what you ask.

Ah - a small misread.

@ECHO OFF

SETLOCAL ENABLEDELAYEDEXPANSION
rem The following settings for the source directory, destination directory, target directory,
rem batch directory, filenames, output filename and temporary filename [if shown] are names
rem that I use for testing and deliberately include names which include spaces to make sure
rem that the process works using such names. These will need to be changed to suit your situation.

SET "sourcedir=u:\your files\t w o"
SET /a newnumber=0
FOR /L %%b IN (1,1,47) DO IF EXIST "%sourcedir%\image%%b.png" ECHO REN "%sourcedir%\image%%b.png" "!newnumber!.png"&SET /a newnumber+=1
GOTO :eof

Proposed commands echoed for verification. Remove the echo keyword to activate following verification. Original filelist presented omits image3.png so result will be 0.png..45.png

Magoo
  • 77,302
  • 8
  • 62
  • 84
  • This will not work for the OP, if by same order, they meant according to Windows Explorer, because `dir`'s `n` sort `/o`rder, will order like this `image1.png`, `image10.png`, `image11.png`, `image12.png`, `image13.png`, `image14.png`, `image15.png`, `image16.png`, `image17.png`, `image18.png`, `image19.png`, `image2.png`, `image20.png` etc. – Compo Jan 23 '21 at 09:11