Click here for important information about

Solved Random batch file renamer...

June 17, 2012 at 10:15:39
Specs: Windows 7, e5300 4GB
I've been pouring over what should be a simple 'file-rename' batch file for the last couple of says, and I find myself stumped. A folder for a certain app uses thirteen loading-screen PNG files, which are named "loading1" through "loading13". To change the order in which they are used by the app, up to now I've had to manually rename them (time-consuming), and I've started looking into a simple batch file that would run before the app, which would randomly rename (renumber) the files in the folder.
In the end, however, I've been unsuccessful, and would appreciate any help here.
Basically all I need the batchfile to do is randomly rename "loading1" through "loading13", simply randomly changing the numbers without overlapping.
Any ideas? I'm totally stumped here...

See More: Random batch file renamer...

June 17, 2012 at 10:45:16
Does it have to be random?

could you use something like
ren c:\loading\loading*.ext 1loading*.ext
ren c:\loading\1loading1.ext loading5.exe
ren c:\loading\1loading2.ext loading9.exe
ren c:\loading\1loading3.ext loading4.exe
ren c:\loading\1loading4.ext loading2.exe
ren c:\loading\1loading5.ext loading6.exe
ren c:\loading\1loading6.ext loading7.exe
ren c:\loading\1loading7.ext loading8.exe
ren c:\loading\1loading8.ext loading3.exe
ren c:\loading\1loading9.ext loading10.exe
ren c:\loading\1loading10.ext loading11.exe
ren c:\loading\1loading11.ext loading1.exe
ren c:\loading\1loading12.ext loading12.exe
ren c:\loading\1loading13.ext loading13.exe

I suppose that you could use the %random% system variable, and apply a gtr lss statement, but the trick I think is how long it would take to run. I would assume as well that it would take a while for the random, and then also for the if statement to ensure non duplications.

:: mike

Report •

June 17, 2012 at 12:36:47
✔ Best Answer
maybe use %random% as mike suggests, in this way:

@echo off & setlocal enabledelayedexpansion
:demo builds the files, use the goto for real files...
:goto :skipdemo
del *.png
for /L %%i in (1,1,13) do >loading%%i.png echo %%i
echo dummy files:
dir /b *.png
ren loading*.png x*.png
dir /b x*.png > temp
type temp
for /f "tokens=*" %%a in (temp) do (
set z=%%a
call :randomizer %%a
echo ren %%a l!nu!
ren %%a l!nu!
goto :eof

set /a r="!random!^%%13"+1
set nu=oading!r!.png
if x!nu! equ %1 echo x!nu!==%1: trying again & goto :randomizer
if exist l!nu! echo l!nu! already there & goto :randomizer

Report •
Related Solutions

Ask Question