Ah boy, randomization.
>Count and log .pdfs in folder.
>Get number of .pdfs to copy by generating a random number from 1 to length of log using modulus.
>Get .pdf to copy by generating a random number from 1 to length of log using modulus.
Either more easily:
-If undefined log variable is selected, repeat without any decrements.
-If defined, process that .pdf and erase it from the log, decrement number of .pdfs to copy and repeat.
Or more properly:
-Process that .pdf and erase it from the log, merge log, decrement number of .pdfs to copy and repeat.
This is the proper method with log merging. You're lucky I felt up to this one, I had already written a couple of the routines.
Code: Select all
@echo off&echo:&color B&title Copy Random Number of Files Randomly by orange_batch&setlocal enableextensions,enabledelayedexpansion
:: Customizable options.
set "_targetfolder=C:\...\Target Folder"
:: Log files in target folder.
for %%x in ("%_targetfolder%\*%_filetype%") do (
set /a _loglength+=1
:: Get random number of files to copy.
set /a _repeats=%random%%%%_loglength%+1
:: Copy a random file. Erase file's log for log merging.
set /a _any=%random%%%%_loglength%+1
echo:f|xcopy "!_log%_any%!" "!_log%_any%:~0,-4!%_suffix%%_filetype%" /v/q/g/h/k/x>nul
:: Merge log.
for /l %%x in (1,1,%_loglength%) do (
if defined _log%%x (
set /a _logcounter+=1
if !_logcounter! NEQ %%x set _log%%x=
set /a _loglength-=1
:: Decrement number of repeats. Repeat if number is greater than 0.
set /a _repeats-=1
if %_repeats% NEQ 0 goto l_repeat