I was bored with the output from file_rand '5_4_12948_1_1_31517_1_4', so I decided to write an alphanumeric version.
This takes a title-name 'Cheetah.DVD.Burner.v2.37-BEAN' and grows a random version 'tD3hr_DNauV_ChVEe_7tDeB_an2A'.
The routine is growing a random title-name
]
The finished random name
]
Chopping long names to 40 char's
]
The idea is to call this from another script, passing it the 'title-name' value. This can be just the 0-day directory-name.
Then the name is 'collapsed' getting rid of . - _ " characters.
The length of this string is gotten and a loop done to generate a random title-name.
XP's cmd shell set %RANDOM% function is too weak @ getting a decent random char, so I used good old msec values again
The routine then sets this value to 'file_rand'.
Final filename:-
[code]
rutBV_eNraE_neAnV_NDhNu_eEDV.rar 9,830KB Winrar archive
[/code]
Uploaded link:-
[code]
[Only registered and activated users can see links. ] [/code]
This can be used in your main script and fed to WinRar for packing:-
[code]
...
START /MIN /W %WINRAR% a %WRCOMP% %WRSIZE% %WRCOMM% -r -ep1 -hp%PASSET% -ad -y -ibck %STORELOCUP%\%file_rand%%EXT% %DIR2%
...
[/code]
Or as I do to a 'renaming section' later on:-
[code]
...
O_TRANS
:: Transform ALL TITLES
IF /I "%TRANSALL%" == "YES" TITLE Transform ALL TITLES
IF /I "%TRANSALL%" == "YES" SET REN_VAL=## ALL TITLES ##
:: Search for '.r00' '.part10.rar' '.rar' and transform to FILE2
IF /I "%TRANSALL%" == "YES" ECHO %FILE3% | FINDSTR /I /R /C:".r[0-9][0-9][^0-9a-z]" > NUL
IF /I "%TRANSALL%" == "YES" IF %ERRORLEVEL% EQU 0 SET FILE2=%file_rand%%FILE3:*.r=.r%
IF /I "%TRANSALL%" == "YES" ECHO %FILE3% | FINDSTR /I /R /C:".rar[^0-9a-z]" > nul
IF /I "%TRANSALL%" == "YES" IF %ERRORLEVEL% EQU 0 SET FILE2=%file_rand%%FILE3:*.rar=.rar%
IF /I "%TRANSALL%" == "YES" ECHO %FILE3% | FINDSTR /I /R /C:".part[0-9][^a-z]" > nul
IF /I "%TRANSALL%" == "YES" IF %ERRORLEVEL% EQU 0 SET FILE2=%file_rand%%FILE3:*.part=.part%
...
[/code]
You can also 'flip-flop' between alpha_rand and file_rand:-
[code]
...
:: Generate a random filename:- '6693_7_2_9_18151_1_2_15726_5' 'Rnmf2_nmf0i_CO0am_O2Smf_Riu'
IF /I "%TRANSALL%" == "YES" if %dizd% leq 49 call %SCRIPTLOC%\Batches\alpha_rand.bat
IF /I "%TRANSALL%" == "YES" if %dizd% geq 50 call %SCRIPTLOC%\Batches\file_rand.bat
...
[/code]
where dizd is a fragment of the title's combined file-size (which will differ for each title and the range is 0-99).
alpha_rand.bat
[code]
@echo off
BREAK ON
VERIFY ON
:: Localise variables and feed name from calling script
setlocal EnableDelayedExpansion & SET a_name=%ARCNAME%
:: Create a random alphanumeric filename for a filename
:: Cheetah.DVD.Burner.v2.37-BEAN >>> tD3hr_DNauV_ChVEe_7tDeB_an2A
::## t e s t #########################
::SET a_name=Cheetah.DVD.Burner.v2.37-BEAN
::SET a_name=Aone.Ultra.Apple.TV.Video.Converter.v4.3
SET a_name=Oxygen.XML.Editor.v10.2.Eclipse.plugin.Incl .Keygen.and.Patch-FALLEN
::## t e s t #########################
:: Set name to title value from pack etc
echo %a_name%>%temp%\a_name.txt
title transforming ... %a_name%
echo. & echo ----- A l p h a T r a n s f o r m ---------------------------------
echo Title-name ... %a_name%
:: ================ FOR LOOP ================
for /f "tokens=*" %%a in (%temp%\a_name.txt) do set a_fn=%%a& call :no-chars
goto :end
:no-chars
:: Strip out " . - _ char's
set a_fna=%a_fn:.=%
set a_fnb=%a_fna:-=%
set a_fna=%a_fnb:_=%
set a_fnb=%a_fna:"=%
set a_fna=%a_fnb: =%
echo Collapsed-name ... %a_fna%
:: trap for a null collapsed name 'ECHOisoff'
if "%a_fna%" == "ECHOisoff" echo ... #### is NULL ####
:: Get just no of chars in collapsed name
echo %a_fna%> %TEMP%\a_name.txt
dir %TEMP%\a_name.txt | find /i "File(s)"> %TEMP%\a_no-chars.txt
:: ================ FOR LOOP ================
for /f "tokens=*" %%b in (%temp%\a_no-chars.txt) do set a_cnt=%%~nxb
set dizb=%a_cnt:~-20%& set a_cnt=%dizb: =%
set a_cnt=%dizb:bytes=%& set dizb=
:: Get rid of CR/LF chars @ 2 bytes
if %a_cnt% gtr 2 set /a a_cnt=a_cnt-2
set b_cnt=%a_cnt%
echo. & echo No of char's ... %a_cnt% & echo.
:: Chop name @ 40 char's
if %a_cnt% geq 40 set a_fna=%a_fna:~0,40%
if %a_cnt% geq 40 set a_cnt=40& set b_cnt=40& echo Chopping @ 40 char's ... %a_fna%
set a_step_cnt=0
:: ================ FOR LOOP ================
:: Step through cnt value from 1 to cnt increments of 1
for /l %%b IN (1,1,%a_cnt%) do set a_step=%%b& call :randomize
goto :eof
:randomize
if %a_step% gtr %a_cnt% goto :eof
:: call get_time's
set a_time_msecb=
call :get_time
:: Get the corresponding char value from fna; eg:- 5 == G etc uses 'setlocal EnableDelayedExpansion'
set /a posa=a_time_msecb-1
set a_rchar=!a_fna:~%posa%,1!
:: echo msecb ... %a_time_msecb% a_rchar ... %a_rchar%
:rtot
:: Format output xxxxx_xxxxx.... up to cnt
if "%a_step_cnt%" == "5" set a_rtot=%a_rtot%_%a_rchar%& set a_step_cnt=0& goto :rtot_end
set a_rtot=%a_rtot%%a_rchar%& goto :rtot_end
:rtot_end
title growing new name ... %a_rtot%
:: traps and counts
set /a a_step_cnt = a_step_cnt + 1
set /a b_cnt=b_cnt - 10
if %b_cnt% leq 0 if %a_cnt% lss 40 set b_cnt=%a_cnt%
if %b_cnt% leq 0 if %a_cnt% geq 40 set b_cnt=40
:: ### returning eof ###
goto :eof
:get_time
:: Use time msec value to get a rand no between 0-9
set a_time=
set a_time=%TIME%
set a_time_msec=%a_time:~10,1%
set /a a_time_msecb=a_time_msec + a_time_msecb
if not %a_time_msecb% gtr %b_cnt% goto :get_time
if %a_time_msecb% gtr %b_cnt% if %a_time_msec% equ %a_time_msecb% set /a a_time_msecb=%a_time_msec%& goto :eof
if %a_time_msecb% gtr %b_cnt% if not %a_time_msec% equ %a_time_msecb% set /a a_time_msecb=a_time_msecb - a_time_msec& goto :eof
goto :eof
:end
title finished alpha-transform ... %a_rtot%
echo. & echo Transformed-name ... %a_rtot% & echo --------------------------------------------------------------------- & echo.
:: Clear variables
set a_time_msecb=& set a_time_msec=& set a_rchar=& set a_fn=& set a_fna=& set a_step_cnt=& set a_cnt=
set a_time=& set a_step=& set a_name=& set b_cnt=& set a_fnb=& set posa=
if exist %temp%\a_name.txt del /f /q %temp%\a_name.txt > nul
if exist %temp%\a_no-chars.txt del /f /q %temp%\a_no-chars.txt > nul
:: Finish localisation and return variable(s)
endlocal & set file_rand=%a_rtot%
:: ########
pause
:: ########
[/code]
Have fun!![]()