Extracting Subscript from Batch Text Lines

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

cottagegeorge

Thread Starter
Joined
Nov 26, 2020
Messages
3
Tech Support Guy System Info Utility version 1.0.0.9
OS Version: Microsoft Windows 10 Home, 64 bit, Build 18363, Installed 20200704092850.000000-240
Processor: AMD A6-7310 APU with AMD Radeon R4 Graphics, AMD64 Family 22 Model 48 Stepping 1, CPU Count: 4
Total Physical RAM: 8 GB
Graphics Card: AMD Radeon(TM) R4 Graphics, 1024 MB
Hard Drives: C: 886 GB (596 GB Free); D: 24 GB (23 GB Free);
Motherboard: LENOVO Nano 5A8, ver SDK0J40700 WIN, s/n PF0R49SS
System: Lenovo, ver LENOVO - 2, s/n PF0R49SS
Antivirus: Windows Defender, Disabled

I have several folders for tv shows I watch. After I watch a show I add the show title and expisode number to the specific show folder. I would like to be able to run a batch script to verify I have not missed an episode or if I accidentally duplicated an episode. I would like to check all the folders with every time I run the script.
Attached are 3 samples of the files I have. Each show is in its own folder under a main folder called TV.
 

Attachments

cottagegeorge

Thread Starter
Joined
Nov 26, 2020
Messages
3
What script code did you write so far?
The code I have written is attached

cd\
c:
@Echo on
setlocal
setlocal enabledelayedexpansion
set prevepstr=""
FOR /F %%f in ('type c:\tv\billions.txt') DO (
echo "--------------------"
set filename=%%f
set var=%%f
set string=%%f
set /a searchcnt=0
set /a searchofcnt=0
set searchVal=.S0
set showstr=""
set foundfile=""
echo.
echo. SHOW NAME IS %filename%
echo. VAR NAME IS %var%
echo. STRING IS %string%
echo. pause2
pause
call :searchsea
)
rem pause

:SEARCHSEA
IF /I "%searchcnt%" EQU "9" (goto eof)
IF /I "%searchcnt%" EQU "0" set searchVal=.S0
IF /I "%searchcnt%" EQU "1" set searchVal=.S1
IF /I "%searchcnt%" EQU "2" set searchVal=.S2
IF /I "%searchcnt%" EQU "3" set searchVal=.S3
IF /I "%searchcnt%" EQU "4" set searchVal=.S4
IF /I "%searchcnt%" EQU "5" set searchVal=.S5
IF /I "%searchcnt%" EQU "6" set searchVal=.S6
IF /I "%searchcnt%" EQU "7" set searchVal=.S7
IF /I "%searchcnt%" EQU "8" set searchVal=.S8
IF /I "%searchcnt%" EQU "9" set searchVal=.S9
set /a searchcnt+=1
set var|FINDSTR /b "var="|FINDSTR /i %searchVal% >nul
if %errorlevel% == 0 GOTO STRINGFND
if %errorlevel% == 1 GOTO SEARCHSEA

:STRINGFND
set "str=%string%"
set "find=*%searchVal%"
echo. str1 is %str%
echo fnd is %find%
call set delete=%%str:%find%=%%
call set str=%%str:%delete%=%%
SET _result=%str:~0,-3%
set dirname=%_result%
Set "sstr=%searchVal%"
SET stemp=%str1%&SET pos=0
echo. dir name is %dirname%
echo
pause

:loop
SET /a pos+=1
ECHO %stemp%|FINDSTR /b /c:"%sstr%" >NUL
IF ERRORLEVEL 1 (
SET stemp=%stemp:~1%
IF DEFINED stemp GOTO loop
SET pos=0
)

SET /A _startchar=%pos
SET _length=6
CALL SET showstr=%%filename:~%_startchar%,%_length%%%
ECHO show str is %showstr%
PAUSE
set seasonstr=%showstr:~1,2%
rem ECHO season str is %seasonstr%
set episodestr=%showstr:~4,2%
ECHO episode str is %episodestr%
set _result=%episodestr:~0,1%
rem echo result is %_result%
if defined %prevepstr% echo prev ep str defined
IF NOT DEFINED prevepstr set prevepstr="%episodestr%"
IF NOT "prevepstr"=="%episodestr%" echo %dirname% has ERROR IN EPISODES>>"C:\tv\showerr.log"
echo rem pause 3
pause
IF NOT "prevepstr"=="%episodestr%" goto eof

set yearstr=%showstr:~1,2%
echo. year str is %yearstr%
set episodestr=%showstr:~4,2%
echo. ep str is %episodestr%
set digit1=%showstr:~0,1%
rem echo. digit 1 is %digit1%
set digit2=%showstr:~1,1%
rem echo. digit 2 is %digit2%
set digit3=%showstr:~2,1%
rem echo. digit 3 is %digit3%
set digit4=%showstr:~3,1%
rem echo. digit 4 is %digit4%
set digit5=%showstr:~4,1%
echo. 1st digit 5 is %digit5%
set digit6=%showstr:~5,1%
echo. 1st digit 6 is %digit6%
set yearstr=%showstr:~0,4%
echo. year str is %yearstr%
set episodestr=%showstr:~4,2%
echo. 1st epis str is %episodestr%
set digit5=%episodestr:~0,1%
echo.2nd digit 5 is %digit5%
set digit6=%episodestr:~1,1%
echo.2nd digit 6 is %digit6%
if %digit5% equ 0 set /A digit6=digit6-1
echo. 3rd digit 5 is %digit5%
if %episodestr% lss 10 set /A episodestr=%episodestr:~5,1%
echo. 2nd epis str is %episodestr%
if %digit5% equ 0 set episodestr=%digit5%%digit6%
echo. 3rd epis str is %episodestr%
if %digit5% equ 0 set episodestr=%digit6%
echo. 4th epis str is %episodestr%
if %digit5% neq 0 set /A episodestr=episodestr-1
echo. 5th epis str is %episodestr%
set prevepstr=%yearstr%%episodestr%
echo. 1st prev show is %prevepstr%
echo show str is %showstr%
echo prev is %prevepstr%
if %episodestr% lss 10 set prevepstr=%yearstr%0%episodestr%
echo. 2nd prev ep str is %prevepstr%
echo. rem pause4
rem pause
goto eof

:eof
 
Joined
Mar 2, 2019
Messages
1,626
Hello, all of this code can be simplified to just few lines.

Since I don't have movie files to perform a test I did a test on random files I found on my disk.

Bellow is sample PowerShell script with code comments to let you understand what it does, copy all of the code bellow and paste it to new txt file and save as ReportMovie.ps1 to location of your choice.

PowerShell:
# TODO: Update path to folder which contains movie files of interest
$MovieRoot = "C:\TV\Condor"

# TODO: Update movie file extension
$MovieExtension = "*.mov"

# TODO: Update path to folder which contains movies you watched (your own made list of watched movies)
$WatchList = "C:\TV\Condor\watched.txt"

# Get a list of movie files and a list of watched videos
$Movies = Get-ChildItem -Path $MovieRoot -Filter $MovieExtension
$Watched = Get-Content -Path $WatchList

# Make sure information message is shown
$InformationPreference = "Continue"

Write-Information -MessageData "INFO: You did not watch following movies:"
Write-Information -MessageData "*****************************************"

# List never watched movies from target movie folder
Compare-Object -ReferenceObject $Watched -DifferenceObject $Movies.Name |
Select-Object -ExpandProperty InputObject

# List all the movies watched more than once
$Duplicates = @{}
$Watched | ForEach-Object { $Duplicates[$_] += 1 }
$Duplicates.Keys | Where-Object { $Duplicates[$_] -gt 1 } | ForEach-Object {
    Write-Warning "You already watched the following movie: $_"
}
Open this script file with code editor of your choice such as VSCode:
Visual Studio Code - Code Editing. Redefined

You need to update first 3 variables to point to the right location before running the script!
These variables are named as follows:
MovieRoot
MovieExtension
WatchList

Once you do so, save this script file and execute it with PowerShell, for example:
.\ReportMovie.ps1

It will show you the list of movies you never watched in target folder and a list of movies you watched more than once.
 
Last edited:

cottagegeorge

Thread Starter
Joined
Nov 26, 2020
Messages
3
Hello, all of this code can be simplified to just few lines.

Since I don't have movie files to perform a test I did a test on random files I found on my disk.

Bellow is sample PowerShell script with code comments to let you understand what it does, copy all of the code bellow and paste it to new txt file and save as ReportMovie.ps1 to location of your choice.

PowerShell:
# TODO: Update path to folder which contains movie files of interest
$MovieRoot = "C:\TV\Condor"

# TODO: Update movie file extension
$MovieExtension = "*.mov"

# TODO: Update path to folder which contains movies you watched (your own made list of watched movies)
$WatchList = "C:\TV\Condor\watched.txt"

# Get a list of movie files and a list of watched videos
$Movies = Get-ChildItem -Path $MovieRoot -Filter $MovieExtension
$Watched = Get-Content -Path $WatchList

# Make sure information message is shown
$InformationPreference = "Continue"

Write-Information -MessageData "INFO: You did not watch following movies:"
Write-Information -MessageData "*****************************************"

# List never watched movies from target movie folder
Compare-Object -ReferenceObject $Watched -DifferenceObject $Movies.Name |
Select-Object -ExpandProperty InputObject

# List all the movies watched more than once
$Duplicates = @{}
$Watched | ForEach-Object { $Duplicates[$_] += 1 }
$Duplicates.Keys | Where-Object { $Duplicates[$_] -gt 1 } | ForEach-Object {
    Write-Warning "You already watched the following movie: $_"
}
Open this script file with code editor of your choice such as VSCode:
Visual Studio Code - Code Editing. Redefined

You need to update first 3 variables to point to the right location before running the script!
These variables are named as follows:
MovieRoot
MovieExtension
WatchList

Once you do so, save this script file and execute it with PowerShell, for example:
.\ReportMovie.ps1

It will show you the list of movies you never watched in target folder and a list of movies you watched more than once.
Thanks for help but I do not want to use POWERSHELL. I wanted a dos batch script that would go through several TV show folders one at a time and run a check on each episode listed and see if any are missing or any are duplicated.I have a script where I can check each folder out but I have to stay and look at each folder. EXAMPLE SHOW TITLE BILLIONS I wanted to do first episode number ie S01E01-goto next episode ie S01E02 -see if is the correct episode-goto next episode ie S01E04 and report episode ie S01E03 is MISSING then goto the NEXT SHOW TITLE IE CONDOR and run same script and so all for all the SHOW TITLES I have.
 
Joined
Mar 2, 2019
Messages
1,626
I do not want to use POWERSHELL
Why not? PowerShell is replacement for batch and doing things with PS is much much easier.

but I have to stay and look at each folder
That's easy doable with powershell, to do the job in one folder and move to the next, and even printing movie title in the console as well as grouping and sorting per folder.

I'm not sure if I understand the rest of your post, but it appears you don't have all the episodes downloaded and in place, anyway I'm not an expert with batch and completing the task with batch is just too messy.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top