K
K
keker13372021-06-06 16:27:16
PowerShell
keker1337, 2021-06-06 16:27:16

How to simultaneously rename numbered files to "number++"?

Good day.
OS: Windows 10.
There are n-th number of files (let's say json), whose names consist of digits-numbers. Let's say I want to insert another file somewhere, for example between 13.json and 14.json. In this case, the new file will be 14.json, and the old 14th and all subsequent files after it should be renamed to the old number + 1. "Bulk Rename Utility" to implement it?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
wisgest, 2021-06-06
@wisgest

setlocal enabledelayedexpansion
set /a first_index = 14

set /a last_index = first_index
:LOOP
if exist %last_index%.json (
  set /a last_index += 1
  goto LOOP
)
set /a last_index -= 1

for /l %%i in (!last_index!, -1, %first_index%) do (
  set /a j = %%i + 1
  ren %%i.json !j!.json
)
endlocal

V
Vasily Bannikov, 2021-06-06
@vabka

You can use "Advanced Rename" in Powertoys or through powershell (I won't tell you a specific script - you need to parse file names)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question