Repeating loop if file name contains string [SOLVED]

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

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

Repeating loop if file name contains string [SOLVED]

#1 Post by AlphaInc. » 09 Aug 2021 02:23

Hello everybody,

With the help of this forum I created a little batch script which runs a command for every mkv-file inside a specific folder and creates an output-file for every file while also increasing a counter. Now I want to expand on this that the script only runs for mkvs in that folder that contain the string *example*. How do you do this:

Code: Select all

@echo on 
setlocal DisableDelayedExpansion

set /A fileCounter=0
	for %%A in (*.mkv) do (
		for /r %%A in (*example*) do ( 			<-- This is where I ran into problems.
			set /A "fileCounter+=1"
			set "name=%%A"
			setlocal EnableDelayedExpansion
			C:\System\Mediainfo\MediaInfo.exe --Inform=file://C:\System\Mediainfo\alphaVideo_template.txt "%%A" >> Output_!fileCounter!.txt
			endlocal
		)
	)
	
exit
Last edited by AlphaInc. on 09 Aug 2021 03:55, edited 1 time in total.

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

Re: Repeating loop if file name contains string

#2 Post by aGerman » 09 Aug 2021 02:54

Code: Select all

for %%A in ("*example*.mkv") do (
Maybe?

Steffen

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

Re: Repeating loop if file name contains string

#3 Post by aGerman » 09 Aug 2021 03:00

FWIW: It's been also for a reason that variable !name! exists. You'll run into trouble once a file name contains exclamation points. I told you about it already.

Steffen

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

Re: Repeating loop if file name contains string

#4 Post by AlphaInc. » 09 Aug 2021 03:55

Yeah that worked. Thank you again.

Post Reply