Move generated files whilst incrementally renaming them (in ascending order)

70 Views Asked by At

Pictures are generated in a directory, each with the same name. I would like to move them to another directory and rename them in an ascending order using a batch file,

e.g. bild1.png -> 1.png, next time bild1.png -> 2.png and so on.

Currently the generated file overwrites the existing file.

What do I have to write in the batch file so it looks in the new directory and renames it with the next number?

For now, the batch file looks like this:

cd C:\stable-diffusion\diffusers\examples\inference

move bild1.png "C:\stable-diffusion\diffusers\examples\inference\Stable Diffusion\"
1

There are 1 best solutions below

0
Magoo On
cd C:\stable-diffusion\diffusers\examples\inference

SET "destdir=C:\stable-diffusion\diffusers\examples\inference\Stable Diffusion"
SET /a sequence=0
:nextseq
SET /a sequence+=1
IF EXIST "%destdir%\%seqence%.png" goto nextseq

move bild1.png "%destdir%\%seqence%.png"

Simply keep incrementing sequence until the destination filename does not already exist.