jeudi 3 septembre 2015

Need help adjusting old code. (Batch random file in subdirectories.)

I wrote some code a long time ago which picks a random file out of a directory and its subdirectories, but I can't for the life of me get it to work only for files of a specific extension. Help!

SET directory="C:\Directory"
SET count=0
FOR /f %%A IN ('DIR %directory% /b /s') DO SET /a count+=1
SET /a randN=%random% %% %count% +1
SET listN=0

FOR /f "tokens=1* delims=:" %%A IN ('DIR %directory% /a-d /b /s^| FINDSTR /n /r . ^| FINDSTR /b "%randN%"') DO (
SET file="%%B"
)

ECHO %file%




Aucun commentaire:

Enregistrer un commentaire