我想获得一个 bat 文件,它将从特定文件夹中打开一个随机文件(带有任何扩展名),但也可以打开该文件夹内所有子文件夹中的文件。还有另一个问题提出了这样的问题(如何在文件夹中打开随机文件,并设置只应打开具有指定文件扩展名的文件?),并提供以下脚本:
@echo off & setlocal
:: start of main
rem Set your path here:
set "workDir=C:\DVDCOVERS"
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 your path.
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 …Run Code Online (Sandbox Code Playgroud)