私はビデオを再生するために古典的なメディアプレーヤーを使います。 このように、プレイリストを再生するためのバッチファイルを作成することができます。
mpc.exe video1.avi video2.avi video3.avi ...
できます。
今、私はランダムにソートされたフォルダ内のすべてのビデオを再生するバッチファイルを作りたいと思います。
何か案が?
ありがとう
回答:
回答№1は0以下のコードは、あなたが現在のディレクトリからファイルを再生していると仮定します、そしてそれはあなたの.aviファイル名のどれもで始まらないと仮定します =
。これらの制限を取り除くのにそれほど時間がかかりません。
フォルダ内のファイル数が多すぎると、最終的にコマンド長が最大許容長8191バイトを超えます。
@echo off
setlocal disableDelayedExpansion
for /f "delims==" %%A in ("set file. 2^>nul") do set "%%A="
for /f "tokens=1* delims=:" %%A in (
"dir /b /a-d *.avi^|findstr /n "^""
) do (
set "file.%%A=%%B"
set "cnt=%%A"
)
set "cmd=mpc.exe"
for /l %%N in (%cnt% -1 1) do call :buildCmd %%N
%cmd%
exit /b
:buildCmd
set /a N=%random% %% %1
set "skip="
if %N% gtr 0 set "skip=skip=%N%"
for /f "%skip% tokens=1* delims==" %%A in ("set file.") do (
set cmd=%cmd% "%%B"
set "%%A="
exit /b
)
回答№2の場合は0
以下のバッチファイルは、ビデオファイルの名前に感嘆符が付いていると失敗します。必要に応じてこれを修正することができます。
@echo off
setlocal EnableDelayedExpansion
rem Store the file names into an array
set cnt=0
for %%a in (*.avi) do (
set /A cnt+=1
set file[!cnt!]=%%a
)
rem Insert the names in the command line in random order
set cmd=mpc.exe
for /L %%a in (%cnt%,-1,1) do (
set /A i=%%a*!random!/32768+1
for %%i in (!i!) do set cmd=!cmd! "!file[%%i]!"
set file[%%i]=!file[%%a]!
)
%cmd%
アントニオ