How to rename multiple . mp3 files by replacing the first argument of each one’s name with a sequential order of numbers

Asked

Viewed 88 times

1

Imagine we had these files in a folder:

2 arquivoABC.mp3
1 arquivoCBA.mp3
3 arquivoBAC.mp3
0 arquivoBCA.mp3

So how could we make the names stay that way:

1 arquivoABC.mp3
2 arquivoCBA.mp3
3 arquivoBAC.mp3
4 arquivoBCA.mp3

How to do using batch?

  • 2

    What would be the ordering rule you want to use?

1 answer

0


Welcome to the SO platform


Supposing that the string in the names (ABC,CBA,BAC,BCA) sane:

  • Exactly those and only those in this sequence

1) Implement a counter

2) list the mp3 files filters in the loop strings in desired sequence: ABC,CBA,BAC,BCA

3) remove the first 2 characters

4) seven the desired sequence

5) renaming


Obs.: Edit the command: Set "_path_mp3=."


Substituting the value: "=." for "=drive:\pasta\onde\tem\os\mp3s"

So that it stays: set "_path_mp3=drive:\pasta\onde\tem\os\mp3s"


| Reordenar.cmd: |

@echo off && setlocal enabledelayedexpansion 

cd /d "%~dp0" & set "_path_mp3=." & cd /d "!_path_mp3!" & set /a "_cnt=0"

for %%F in (ABC,CBA,BAC,BCA)do for /f "tokens=*delims= " %%i in ('where .:"*.mp3" ^| find /i "%%F"')do (
     set /a "_cnt+=1" && set "_arq_=%%~ni"
     set "_cmd_ren_[!_cnt!]=rename "%%~fi""
     set "_arq_[!_cnt!]=!_arq_:~2,-3!%%F.mp3")

for /l %%L in (1 1 !_cnt!)do !_cmd_ren_[%%L]! "%%L !_arq_[%%L]!" & where .:"%%L !_arq_[%%L]!" /t

| Resulta: |


inserir a descrição da imagem aqui


Browser other questions tagged

You are not signed in. Login or sign up in order to post.