简体   繁体   中英

How to play random video files in a folder and move on to the next folder and do the same with batch script?

This is bit confusing so I will try to explain.. (btw, I am using windows 7 pc).

I grew up watching shows I loved and over the years I downloaded many shows to my external Harddrive. I have been searching for a way to play random episodes for each of my shows through Windows Media Player but I couldn't seem to find anything.

Couple months back, someone helped me by writing a batch script that almost does exactly what I want but it doesn't seem to play random episodes for my shows.

For example, let's say I have X shows in a drive (For example, Simpsons, Critic, BillNye, Garfield, Batman etc..)

In each of those shows, theres X amount of Episodes (For example Simpsons has 85 episodes, Critic 24 episodes, Billnye 100 episodes, garfield 64 episodes etc..)

I was looking for a way so that the script will look into the Simpsons folder, then pick 1 random episode, then move on to the Critic folder, pick 1 random episode, and move on to BillNye folder and so forth.

When this is all done going through all my shows it outputs a playlist file. So all I would have to do is load the playlist into my Windows Media Player instead of spending a long time manually picking out each episodes to watch.

Well, couple months back someone wrote this for me but after weeks of testing, it doesn't seem to be truly random because it seems to repeat some of the same episodes from the last playlist. (Some folders have over 100 shows so I couldn't understand why it would still play the same episode if it was trying to be random)

I tried to get back to the person, but I lost contact and if anyone out there can assist me... ^_^

Here is this script:

SET extensionList=avi mp4 mkv
SET cnt=0
:Loop
  SET /A cnt+=1
IF EXIST %cnt%.m3u GOTO Loop
>%cnt%.m3u ECHO.#EXTM3U
FOR /D %%a IN (c:\testing\*) DO CALL :PickFile "%%a"
GOTO :EOF

:PickFile
SET searchList=
FOR %%b IN (%extensionList%) DO CALL SET searchList=%%searchList%% "%~1\*.%%b"
FOR /F %%b IN ('2^>NUL DIR /A-D-H-S %searchList% ^| FIND "File(s)"') DO SET limit=%%b
SET /A fileNum=(%random% %% limit) + 1
FOR /F "tokens=2 delims=:" %%b IN ('2^>NUL DIR /A-D-H-S/B %searchList% ^| FINDSTR /N ".*" ^| FINDSTR "^%fileNum%:"') DO ^
CALL :AddList %1 "%%b" >>%cnt%.m3u
GOTO :EOF

:AddList
@ECHO.#EXTINF:-1,%~n2
@ECHO.%~f1\%~2
@GOTO :EOF

In this script, it outputs an *.m3u file X amount of times for each X amount of times I wish to click.

The problem with this script is that it seems to repeat certain episodes for some shows and I'm wondering if this can be modified a little bit so that it can be truly random, or a way so that the last episode wouldn't be repeated again on the next playlist?

I hope I didn't confuse anyone, and I don't know much about programming. I tried learning C++ in high school years ago but I had such a hard time. I just know basics but if anyone can help me~ I'll be forever in your debt.

If anyone have any questions I'll be more than happy to respond asap~ Thanks again ^_^

I think some testing is needed here :)

This is an alternative to getting a random number

%random% * 10 / 32768 + 1

After a few runs of that, I found it does yield slightly better averages than the version you are running.

To test I did this 1000 times for each version

Tammy Script

setlocal enabledelayedexpansion
for /l %%a in (1,1,1000) do (
call :RAND
echo !num! >>tammy.txt
)

:RAND
set /a num=(%random% %% 10) + 1

Bali Script

setlocal enabledelayedexpansion
for /l %%a in (1,1,1000) do (
SET /A num=!random! * 10 / 32768 + 1
echo !num! >>bali.txt
)

Then, count the number of times each number appears (1-10 in this case)

for /l %%a in (1,1,10) do (
find /c "%%a" tammy.txt
) >>tammycount.txt

for /l %%b in (1,1,10) do (
find /c "%%b" bali.txt
) >>balicount.txt

Then compare results

tammycount.txt

---------- R2.TXT: 203

---------- R2.TXT: 103

---------- R2.TXT: 82

---------- R2.TXT: 101

---------- R2.TXT: 95

---------- R2.TXT: 87

---------- R2.TXT: 107

---------- R2.TXT: 118

---------- R2.TXT: 104

---------- R2.TXT: 99

balicount.txt

---------- R.TXT: 201

---------- R.TXT: 90

---------- R.TXT: 91

---------- R.TXT: 101

---------- R.TXT: 108

---------- R.TXT: 97

---------- R.TXT: 101

---------- R.TXT: 105

---------- R.TXT: 106

---------- R.TXT: 106

As you can see, balicount shows slightly more average numbers (as you would expect), so maybe worth trying with my version and see if it's any better.

Obviously you would have to do this a lot of times to get any real results but it might be worth doing if you have some time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM