Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- REM can't remember which episode you watched last? this batch will list all video files of the current folder and subfolders, sort them alphabetical and then play back the next episode.
- REM copy this text into a text file and change the file ending to .bat
- REM update 4: How to go through subfolders: create a shortcut to this bat file and add -sub after the target as command line parameter.
- REM you can change the target directory of the shortcut to another folder if you like. e.g. the .bat file in somefolder and the loaded movie files in someotherfolder.
- REM if you have lots of folders to go through, use this other batch file to create a shortcut, linking to a random folder: https://pastebin.com/vCAMYQD9
- REM summary of previous updates: "enable delayedexpansion" doesn't work together with paths that include exclamation mark; findstr uses backslash as escape character so that doesn't work too.
- @echo off
- if exist next.txt goto play
- REM if next.txt is not present, create a new file with all .avi, .mkv, .mov and .mp4 files in this folder and all sub folders (/s)
- REM /b reduces the dir command to just the file name, /s searches through all sub folders and writes the complete path into the list
- REM add -sub to the shortcut to activate the search through subfolders
- if "%1"=="-sub" goto yes
- goto no
- :yes
- dir *.mkv /b /s > temp.txt
- dir *.mp4 /b /s >> temp.txt
- dir *.avi /b /s >> temp.txt
- dir *.mov /b /s >> temp.txt
- echo included subfolders
- goto continue
- :no
- dir *.mkv /b > temp.txt
- dir *.mp4 /b >> temp.txt
- dir *.avi /b >> temp.txt
- dir *.mov /b >> temp.txt
- :continue
- REM sorting the result in case file formats are mixed
- sort temp.txt > list.txt
- del temp.txt
- REM if exists watched.txt compare with list.txt
- REM put not matching entries in next.txt
- if exist list.txt (
- if exist watched.txt (
- echo filtering next.txt
- REM the given example for findstr weren't helpful. g: is the key(s) and the second parameter is the list to check for the key(s)
- REM if not exist next.txt echo.> next.txt
- REM note: removed findstr because it doesn't work with complete paths as backslash is an escape char
- for /f "tokens=*" %%f in (watched.txt) do (
- if exist %%f (
- echo %%f>> watched2.txt
- echo filtering "%%f"
- echo @echo off> sort.bat
- echo for /f "tokens=*" %%%%d in ^(list.txt^) do ^(>> sort.bat
- echo if not "%%%%d"=="%%f" ^(>> sort.bat
- echo echo %%%%d^>^> list2.txt>> sort.bat
- echo ^)>> sort.bat
- echo ^)>> sort.bat
- echo del list.txt>> sort.bat
- echo ren list2.txt list.txt>> sort.bat
- call sort.bat
- )
- )
- del watched.txt
- ren watched2.txt watched.txt
- echo filter complete
- del sort.bat
- )
- )
- ren list.txt next.txt
- :play
- REM if playlist was already created, pick next title and play, ignore the rest
- set /p line=< next.txt
- for /f "tokens=*" %%a in (next.txt) do (
- REM check if line is not empty
- if not "%%a" == "" (
- if "%line%"=="%%a" (
- REM first line entry is started/played
- echo starting: %%a
- start "" "%%a"
- REM put entry in watched.txt
- echo %%a>> watched.txt
- ) else (
- REM rest of the lines are copied into a new file, effectively reving the first line
- echo %%a>> temp.txt
- )
- )
- )
- del next.txt
- ren temp.txt next.txt
Add Comment
Please, Sign In to add comment