i'd like to create a batch file for opening a random file within a folder and all of it's subfolders.
I'd also like to add "exception folders" - folders, which are excluded from the random opening.
Currently, i'm using this:
@echo off
setlocal
:: Create numbered list of files in a temporary file
set "tempFile=%temp%\%~nx0_fileList_%time::=.%.txt"
dir /b /s /a-d %1 | findstr /n "^" >"%tempFile%"
:: Count the files
for /f %%N in ('type "%tempFile%" ^| find /c /v ""') do set cnt=%%N
call :openRandomFile
:: Delete the temp file
del "%tempFile%"
exit /b
:openRandomFile
set /a "randomNum=(%random% %% cnt) + 1"
for /f "tokens=1* delims=:" %%A in (
'findstr "^%randomNum%:" "%tempFile%"'
) do start "" "%%B"
exit /b
It works perfectly for the random opening, but i'm not sure how i could exclude some of the subfolders within the specific directory.
Thank you in advance for your help! :)
Aucun commentaire:
Enregistrer un commentaire