Set Global and "local" Counter

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
AlphaInc.
Posts: 19
Joined: 15 Apr 2021 08:15

Set Global and "local" Counter

#1 Post by AlphaInc. » 06 Aug 2021 04:56

Hello everybody,

I have created a template for MediaInfo to output specific information about the video files inside a specific folder. The output will then be written to a txt-file.
This is the command I Use:

Code: Select all

for %%A in (*.mkv) do C:\System\Mediainfo\MediaInfo.exe --Inform=file://C:\System\Mediainfo\template1.txt %%A >> Output1.txt
for %%A in (*.jpg) do C:\System\Mediainfo\MediaInfo.exe --Inform=file://C:\System\Mediainfo\template2.txt %%A >> Output2.txt
the template (template1.txt) for MKV's looks like this:

Code: Select all

General;--------------------------------------------------------------------\n%fileCounter%\n--------------------------------------------------------------------\n\nFile-Name...............: %CompleteName%\nFile-Size...............: %FileSize/String%\nDuration................: %Duration/String%\nOverall-Bitrate.........: %OverallBitRate/String%\n
Video;Video-Codec.............: %Format/String%\nVideo-Bitrate...........: %BitRate_Maximum/String%\nVideo-Auflösung.........: %Width%x%Height%\nVideo-Size..............: %StreamSize/String%\n
Audio;Audio-Langauge %audioCounter%........: %Language/String%\nAudio-Format %audioCounter%..........: %Format/String% (%CodecID%)\nAudio-Bitrate %audioCounter%.........: %BitRate/String% (%SamplingRate/String%)\nAudio-Size %audioCounter%............: %StreamSize/String%\n
Text;Text-Bitrate %textCounter%..........: %Language/String%\nText-Codec %textCounter%............: %Format/String%\nText-Bitrate %textCounter%..........: %BitRate/String%\nText-Size %textCounter%.............: %StreamSize/String%\n
File_End;\n
And the template (template2.txt) for JPGs looks like this:

Code: Select all

General;--------------------------------------------------------------------\n%fileCounter%\n--------------------------------------------------------------------\n\nFile-Name...............: %CompleteName%\nPhoto-Codec.............: %Format/String%\n
Image;Photo-Auflösung.........: %Width%x%Height%\nPhoto-Size..............: %StreamSize/String%\n
File_End;\n
Now i want to expand this by setting different counters. I want the script to count for all files (it should just go File 1, File 2, File 3, etc.) and also the different audio and text-information but for those two, the counter should be reset after every file. I thought about something like this but I'm not sure how to do:

Code: Select all

set /A fileCounter=0 for
   set /B audioCounter=0
   set /C textCounter=0
      for %%A in (*.mkv) do C:\System\Mediainfo\MediaInfo.exe --Inform=file://C:\System\Mediainfo\template1.txt %%A >> Output1.txt
   set /B audioCounter=0
   set /C textCounter=0
      for %%A in (*.jpg) do C:\System\Mediainfo\MediaInfo.exe --Inform=file://C:\System\Mediainfo\template2.txt %%A >> Output2.txt
   set /B audioCounter=0
   set /C textCounter=0
But that specific code did not work (it outputs the file and leves everything empty where my counters have been set, probably because the mediainfo template uses this kind of syntax.

aGerman
Expert
Posts: 4245
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Set Global and "local" Counter

#2 Post by aGerman » 06 Aug 2021 11:32

Don't get it, sorry. However, there's no such things like SET /B or SET /C.

Steffen

AlphaInc.
Posts: 19
Joined: 15 Apr 2021 08:15

Re: Set Global and "local" Counter

#3 Post by AlphaInc. » 06 Aug 2021 12:32

What I meant is to set a counter (With SET /B and SET /C I was trying to set a counter in the head of the tool and define it as 0 to later increase)

When executing the commands listed in the script the counter should increase with every file (fileCounter) respectively every audio (audioCounter) and Subtitle (textCounter).

IcarusLives
Posts: 132
Joined: 17 Jan 2016 23:55

Re: Set Global and "local" Counter

#4 Post by IcarusLives » 06 Aug 2021 12:54

You're missing the entire fundamental of set /a.

Code: Select all

set /a "var=1"

set /a "var[1]=var + 1"
set /a "var[2]=var[1] + 2"

set /a "var+=1"
You don't change the command. You create an array and add to each variable accordingly.

ShadowThief
Expert
Posts: 1042
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: Set Global and "local" Counter

#5 Post by ShadowThief » 06 Aug 2021 13:23

The "a" in "set /a" is short for "arithmetic."

AlphaInc.
Posts: 19
Joined: 15 Apr 2021 08:15

Re: Set Global and "local" Counter

#6 Post by AlphaInc. » 06 Aug 2021 13:52

Ah okay, that's how i set the counter. And do i implement "var" in a text file to increase ?

I even have troubles to even increase the counter for fileCounter (as shown in my mediainfo-template. When I execute the script like that the line stays empty without anything.

Code: Select all

@echo off

set /a fileCounter=0
	for %%A in (*.mkv) do (
		set /a fileCounter=fileCounter+1
		C:\System\Mediainfo\MediaInfo.exe --Inform=file://debug.txt %%A >> Output1.txt
		)
exit

Post Reply