Z
Z
Zharkyn972020-08-08 19:34:48
cmd/bat
Zharkyn97, 2020-08-08 19:34:48

CMD/BAT - Batch rename files (.jpg) in different folders (BAT)?

Look, I have folders:
asteklo1, asteklo2, asteklo3, asteklo4...
each of them contains 2 files (.jpg)
I need a way (the same bat) to batch rename all these files (.jpg) - > in the name of the folder and with an underscore with file numbering
Example:
folder "asteklo1", it should contain "asteklo1_1" and "asteklo1_2"
and so with each folder, someone fumbles for this topic?
I just batch created all these folders with different names:
for /f %%i in (list.txt) do @md "%%~i"
well, of course, this list.txt contained all the folder names in lines

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
res2001, 2020-08-09
@res2001

More or less like this:

@echo off
setlocal enabledelayedexpansion
for /d %%a in (*) do (
  set "count=1"
  for %%b in ("%%~a\*.jpg") do (
     ren "%%~b" "%%~na_!count!%%~xb"
     set /a "count=!count! + 1"
  )
)

Now there is no Windows at hand - I can not test it.
No folder list files are required. Script checks all subfolders in current folder and renames all jpg's

R
Roman Mirilaczvili, 2020-08-09
@2ord

I won’t suggest a ready-made solution on CMD - I myself work on Linux.
Algorithm:

Нужно пройтись по всем директориям по имени, начинающихся с "asteklo", для каждой из которых:
  сохранить имя директории в переменной
  обнулить счётчик порядкового номера в переменной
  В цикле, проходясь по каждому файлу в директории
    увеличить счётчик +1 в переменной
    составить новое имя файла в переменной: имя_директории "_" счётчик_порядкового_номера ".jpg"
    переименовать файл в новое имя

Help: https://ss64.com/nt/for.html and https://en.wikibooks.org/wiki/Windows_Batch_Script...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question