I made a batch file that displays the names of all the videos available in the current folder and asks you which one to play. Then based on your choice it plays that particular video and logs that video's name into the file "watched.txt". So, basically I want "watched.txt" to keep a record of all the watched video names in decreasing order of episode numbers. If a video was watched previously it should not be logged again into the file watched.txt.
Also, all the video names has the same structure as "Suits.S03Exx.720p" where only xx (i.e, the episode number) changes. xx is always a two digit integer (like 01, 02, 03, ...,11, ...).
The batch script (provided at last) reads the file "watched.txt" line by line using a for loop.
Below are the contents of the file "watched.txt" for now:
Suits.S03E10.720p
Suits.S03E09.720p
Suits.S03E08.720p
Suits.S03E07.720p
Suits.S03E06.720p
Suits.S03E05.720p
Suits.S03E04.720p
Suits.S03E03.720p
Suits.S03E02.720p
Suits.S03E01.720p
Now, when I play episode no: 08 through my batch file (file name: "Suits.S03E08.720p") for the second time, it is being logged again into watched.txt which is not what I want. It produces below "watched.txt" file:
Suits.S03E08.720p
Suits.S03E10.720p
Suits.S03E09.720p
Suits.S03E08.720p
Suits.S03E07.720p
Suits.S03E06.720p
Suits.S03E05.720p
Suits.S03E04.720p
Suits.S03E03.720p
Suits.S03E02.720p
Suits.S03E01.720p
However, I was expecting the same watched.txt with no change in its contents as episode no 08 was played earlier and is already present in it.
I inspected the temporary files (temp1.txt, temp2.txt & temp3.txt) used in the manipulation of watched.txt (by commenting out these statements from the batch file for testing purposes: del temp1.txt, del temp2.txt, del temp3.txt)
The first temporary file temp1.txt was found empty. Instead, I was expecting it to be having below contents as per the logic of my batch file:
Suits.S03E10.720p
Suits.S03E09.720p
The second temporary file temp2.txt was found to be having below contents:
Suits.S03E10.720p
Suits.S03E09.720p
Suits.S03E08.720p
Suits.S03E07.720p
Suits.S03E06.720p
Suits.S03E05.720p
Suits.S03E04.720p
Suits.S03E03.720p
Suits.S03E02.720p
Suits.S03E01.720p
Instead, I was expecting temp2.txt to be empty as per the logic of my batch file.
Now, the third temporary file temp3.txt was found to be having below contents:
Suits.S03E08.720p
Suits.S03E10.720p
Suits.S03E09.720p
Suits.S03E08.720p
Suits.S03E07.720p
Suits.S03E06.720p
Suits.S03E05.720p
Suits.S03E04.720p
Suits.S03E03.720p
Suits.S03E02.720p
Suits.S03E01.720p
Instead, I expected temp3.txt to be empty as per the logic of my batch file.
Below is the end portion of the Batch file (I have not attached full code) I'm using with these inputs justPlayedName=Suits.S03E08.720p & justPlayedNumber=08 (these inputs are coming from initial portions of the full batch file):
break> temp1.txt
break> temp2.txt
break> temp3.txt
setlocal ENABLEDELAYEDEXPANSION
for /f "tokens=*" %%S in (watched.txt) do (
set watchedName=%%S
set watchedNumber= !watchedName:~10,2!
if !watchedNumber! EQU !justPlayedNumber! ( goto EOFL_2 )
if !watchedNumber! GTR !justPlayedNumber! (
echo !watchedName! >> temp1.txt
)
if !watchedNumber! LSS !justPlayedNumber! (
echo !watchedName! >> temp2.txt
)
)
endlocal
type temp1.txt > temp3.txt
echo %justPlayedName% >> temp3.txt
type temp2.txt >> temp3.txt
type temp3.txt > watched.txt
:EOFL_2
del temp1.txt
del temp2.txt
del temp3.txt
pause
Someone, please tell me where is the issue?