So i have this so far.
SETLOCAL EnableDelayedExpansion
for /f "tokens=* delims=" %%a in ('dir /b *.mp3') do ren "!random:~-2! %%a"
it seams to work well. but, I'd like to be able to re-run it and have it re-randomized the files already randomized and include any new files I've put into the folder.
rename leading with random number. then re-randomize later.
Moderator: DosItHelp
Re: rename leading with random number. then re-randomize lat
well i posted cause i didn't think i'd be able to figure it out but I got this so far and i think its solid. can anyone see any problems?
@echo off
SETLOCAL EnableDelayedExpansion
for /f "tokens=* delims=" %%a in ('dir /b *.mp3') do (
set string=%%a
set check1=!string:~0,2!
if !check1! lss 100 (ren "%%a" "!random:~-2! !string:~3,200!") else (ren "%%a" "!random:~-2! %%a")
)
@echo off
SETLOCAL EnableDelayedExpansion
for /f "tokens=* delims=" %%a in ('dir /b *.mp3') do (
set string=%%a
set check1=!string:~0,2!
if !check1! lss 100 (ren "%%a" "!random:~-2! !string:~3,200!") else (ren "%%a" "!random:~-2! %%a")
)
Re: rename leading with random number. then re-randomize lat
You could try this:
Note that the code will end up in an infinite loop if you've got more than a hundred .mp3 files in the folder.
Regards
aGerman
Code: Select all
@echo off &setlocal
for /f "delims=" %%a in ('dir /b *.mp3') do (
set "string=%%~a"
call :proc
)
pause
goto :eof
:proc
SetLocal EnableDelayedExpansion
set "name=!string!"
echo(!string!|findstr /rbc:"[0-9][0-9] ." >nul &&(
set "string=!string:~3!"
)
:loop
set "newname=%random:~-2% !string!"
if exist "!newname!" goto loop
ren "!name!" "!newname!"
EndLocal
goto :eof
Note that the code will end up in an infinite loop if you've got more than a hundred .mp3 files in the folder.
Regards
aGerman