nested for loop not working as hoped

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

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

nested for loop not working as hoped

#1 Post by zimbot » 07 Mar 2019 11:35

friends I am attempting something that ...almost works

I wish to batch the creation of mp4 from Prores mov from a nested dir up to a mp4 dir
here is my dir structure

My "start point is Directory of D:\ark
inside there exist D:\ark\prores
which contains many dir like so
D:\ark\prores\ape
D:\ark\prores\cow
and each of those has many many file.mov like so
--- ape
D:\ark\prores\ape\ape_1.mov
D:\ark\prores\ape\ape_2.mov

--- cow
D:\ark\prores\cow\cow_1.mov
D:\ark\prores\cow\cow_2.mov

my goal is to make a mp4 dir like so
D:\ark\mp4 ::: this I am successful at hooRay
then based on each dir ( ape , cow ) found in prores
make a dir in ark next to prores like so

D:\ark\mp4\ape
D:\ark\mp4\cow
then populate those with my mp4 like so
D:\ark\mp4\ape\ ...many mp4 ape_1.mp4 , ape-2.mp4
D:\ark\mp4\cow\ ...many mp4 cow-1.mp4 , cow_2.mp4

it is my 2nd for loop , my nested for which is not working

any assistance would be appreciated

it is very possible that a totally diffrent approach would be wiser this is my 5th version
thankS!

Code: Select all


@echo off
REM 3.2019		js :::   		ark 1
Setlocal EnableDelayedExpansion 
REM ----------------------------------0\  
rem drag in ark , makes a mp4 next to prores , cd into prores 
rem for each dir in prores (ape)  makes a dir in mp4 (ape) cd into prores/ape
rem makes mp4 in mp4/ape


rem ----------------------------------0/


echo * ------5----------------------------------------------------------------------*
echo ***                   You will be asked to drag here:                       *** 
echo *** 						                         ***
echo ** just drag your dir to this shell , have focus in the shell and hit enter ***

echo ark
rem voice ark 


rem set logfile=make-hash.txt

set /p srcDir=Drag your Source Directory here:%=%
@echo %scrcDir%
REM pause
cd /D %srcDir%
dir
REM pause
rem make the mp4 dir under ark
mkdir  mp4

cd %srcDir%\prores

REM voice WORKING
      REM for /d %%X in (%srcDir%\prores\*) do echo %%X 
	rem for /D "delims=" %%i in ('dir %srcDir%\prores\*') do (
	rem echo %%i
REM --------------make the dir
FOR /D  %%G in ("*") DO ( 
Echo We found %%~nxG
mkdir  %srcDir%\mp4\%%~nxG


echo my goal in dir is %srcDir%\prores\%%~nxG
REM *** so far so good what is not happening is after this
	rem cd %srcDir%\prores\%%~nxG
echo The current directory is %CD%

 	REM -----------make file
	for /f %%a IN ('%srcDir%\prores\%%~nxG\*.mov') do  (
	echo found file %%a
	ffmpeg -i %srcDir%\prores\%%~nxG\%%a.mov %srcDir%\mp4\%%~nxG\%%a.mp4

rem end for 2
        )

rem end for 1
)




I am successful in making the mp4 dir and making the ape , cow dir but I am not currently creating the mp4 files Inside those dir

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

Re: nested for loop not working as hoped

#2 Post by Squashman » 07 Mar 2019 12:26

Your second for command is trying to execute a command because you are using the /F option and using single quotes within the in clause. You don't have a valid command within the in clause. Just remove the /F option and change the single quotes to double quotes which will execute a standard FOR command to find all the .mov files.
Then with your FFMPEG use the proper command modifiers with the %%a variable.

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

Re: nested for loop not working as hoped

#3 Post by zimbot » 07 Mar 2019 15:17

so cool
and I am zero suprised that part of the solution was dbl quotes
it makes sense to me now my mistake with the for needing to be standard
and i had my path stuff all wrong
I figured that out by doing the "echo my thing is -- yada yada

and proper form of %%a ... can you believe I had that - for a moment- i had that as %%a~na.mp4 ....ummm oPPS!
here is final vers 7 ... thank you squashman . you da man!

Code: Select all


@echo off
REM 3.2019		js :::   		ark 1
Setlocal EnableDelayedExpansion 
REM ----------------------------------0\  
rem drag in ark , makes a mp4 next to prores , cd into prores 
rem for each dir in prores (ape)  makes a dir in mp4 (ape) cd into prores/ape
rem makes mp4 in mp4/ape


rem ----------------------------------0/


echo * ------7----------------------------------------------------------------------*
echo ***                   You will be asked to drag here:                       *** 
echo *** 						                         ***
echo ** just drag your dir to this shell , have focus in the shell and hit enter ***

echo ark
rem voice ark 


rem set logfile=make-hash.txt

set /p srcDir=Drag your Source Directory here:%=%
@echo %scrcDir%
REM pause
cd /D %srcDir%
dir
REM pause
rem make the mp4 dir under ark
mkdir  mp4

cd %srcDir%\prores

REM voice WORKING
      REM for /d %%X in (%srcDir%\prores\*) do echo %%X 
	rem for /D "delims=" %%i in ('dir %srcDir%\prores\*') do (
	rem echo %%i
REM --------------make the dir
FOR /D  %%G in ("*") DO ( 
Echo We found %%~nxG
mkdir  %srcDir%\mp4\%%~nxG


echo my goal in dir is %srcDir%\prores\%%~nxG
	rem cd %srcDir%\prores\%%~nxG
echo The current directory is %CD%

 	REM -----------make file
	for %%a IN ("%srcDir%\prores\%%~nxG\*.mov") do  (
	echo found file %%a
	rem echo my thing is     ffmpeg -i %srcDir%\prores\%%~nxG\%%a.mov %srcDir%\mp4\%%~nxG\%%~na.mp4
        rem echo my new thing is ffmpeg -i %%a  %srcDir%\mp4\%%~nxG\%%~na.mp4
        ffmpeg -i %%a  %srcDir%\mp4\%%~nxG\%%~na.mp4

        )


)





Post Reply