[Solved] Using IF statements with multiple conditions


I suppose you could use delayed expansion and remove the nested If statements too:

@Echo Off
SetLocal EnableDelayedExpansion
Set "i="
For /F "Delims=" %%A In ('Where .:???.mp3 2^>Nul')Do (
    If 1%%~nA Gtr 1000 Set "i=1"
    If 1%%~nA Gtr 1003 Set "i=2"
    If 1%%~nA Gtr 1006 Set "i=3"
    If 1%%~nA Gtr 1020 Set "i=4"
    If 1%%~nA Gtr 1030 Set "i=5"
    If 1%%~nA Gtr 1045 Set "i="
    If Defined i Ren "%%A" "%%~nA-chapter-!i!%%~xA"
)

In the example above, I have used the Where command to limit the returned metavariables to those with 3 character basenames. This will prevent cycling through any renamed files again, (as you were renaming them in the same directory with the same extension, which would still match your *.mp3 pattern).

Please note that this only filters .mp3 files with three characters, it does not make any determination that those characters are each integers. I’ll leave you to decide if you wish to implement something like that yourself.

solved Using IF statements with multiple conditions