Como fazer este script ler todas as subpastas

0

Encontrei script abrindo arquivos aleatórios . Eu mudei uma coisa e agora é aberto arquivo aleatório de C: / Alguém pode me dizer como alterá-lo para abrir o arquivo aleatório de C: / e todas as subpastas?

@echo off & setlocal
:: start of main
rem Set your path here:
set "workDir=C:\"

rem Read the %random%, two times is'nt a mistake! Why? Ask Bill.
rem In fact at the first time %random% is nearly the same.
@set /a "rdm=%random%"
set /a "rdm=%random%"

rem Push to
pushd "%workDir%"

rem Count all files in your path. (dir with /b shows only the filenames)
set /a "counter=0"
for /f "delims=" %%i in ('dir /b ^|find "."') do call :sub1

rem This function gives a value from 1 to upper bound of files
set /a "rdNum=(%rdm%*%counter%/32767)+1"

rem Start a random file
set /a "counter=0"
for /f "delims=" %%i in ('dir /b ^|find "."') do set "fileName=%%i" &call :sub2

rem Pop back from your path.
popd "%workDir%"

goto :eof
:: end of main

:: start of sub1
:sub1
rem For each found file set counter + 1.
set /a "counter+=1"
goto :eof
:: end of sub1

:: start of sub2
:sub2
rem 1st: count again,
rem 2nd: if counted number equals random number then start the file.
set /a "counter+=1"
if %counter%==%rdNum% (start "" "%fileName%")
goto :eof
:: end of sub2

:: -snap--- end of batch
    
por k073l 16.08.2016 / 18:34

1 resposta

2

Você precisa da /s switch

Alterar

for /f "delims=" %%i in ('dir /b ^|find "."') do call :sub1

para

for /f "delims=" %%i in ('dir /b /s ^|find "."') do call :sub1

e altere

for /f "delims=" %%i in ('dir /b ^|find "."') do set "fileName=%%i" &call :sub2

para

for /f "delims=" %%i in ('dir /b /s ^|find "."') do set "fileName=%%i" &call :sub2
    
por 16.08.2016 / 19:24