in a for loop just 2 kind of extentions

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
zimbot
Posts: 7
Joined: 08 Nov 2018 14:05

in a for loop just 2 kind of extentions

#1 Post by zimbot » 08 Nov 2018 14:13

Friends

I have a for loop where i loop through a dir full of video files - call an ffmpeg cmd and make mp4

I do that like so ( a snippit )

or /f %%a IN ('dir /b *.*') do
now this does my command on every file in that dir ( that i have already cd'd to )
it will work nicely on iether f.avi or f.mov ..... good
but it will *also* try to make a mp4 from a txt file ....which is not good

here is my question can i limit it to 2 declared extentions
like
or /f %%a IN ('dir /b *.avi OR *.mov') do

meaning it works on all file.avi all file.mov but ONLY those 2

so far I have solved this by 2 for loops
1 for *.mov and 1 for *.avi

thanks

jS

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: in a for loop just 2 kind of extentions

#2 Post by Squashman » 08 Nov 2018 14:26

You were close.
You can do this two ways.

Code: Select all

FOR %%G IN (*.avi *.mov) do .....
or

Code: Select all

FOR /F "delims=" %%G IN ('dir /a-d /b *.avi *.mov') do....

zimbot
Posts: 7
Joined: 08 Nov 2018 14:05

Re: in a for loop just 2 kind of extentions

#3 Post by zimbot » 08 Nov 2018 14:49

ok thanks but now I have this problem

my ffmpeg cmd was this


ffmpeg.exe -i %%a -y -vcodec libx264 -b:v 4110000 -pix_fmt yuv420p -g 12 -bf 3 -b_strategy 1 -coder 1 -qmin 10 -qmax 51 -sc_threshold 40 -me_range 16 -me_method hex -subq 5 -i_qfactor 0.71 -qcomp 0.6 -qdiff 4 -s 1280x720 -acodec aac -strict -2 -ar 48000 -b:a 128k %destDir%\%%~na.mp

so when i did
or /f %%a IN ('dir /b *.*') do

and had dog.mov i would end with dog.mp4

now with
FOR %%G IN (*.avi *.mov) do
what do i do for the " %%~na.mp4 "
because now if i have 3 mov ...it overwrites and leaves the last as actually %%~na.mp4
i tried %%~ng.mp4 and i get a file actually named %%~ng.mp4

thanks

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: in a for loop just 2 kind of extentions

#4 Post by Squashman » 08 Nov 2018 14:52

I always use an UPPERCASE G for my FOR variable. The FOR variable is case sensitive. It also helps with visually identifying which letters are the command modifiers and which one is the FOR variable.

zimbot
Posts: 7
Joined: 08 Nov 2018 14:05

Re: in a for loop just 2 kind of extentions

#5 Post by zimbot » 08 Nov 2018 14:59

ummmph

yes
%%~nG.mp4

works nicely

thanks again!

Post Reply