Home > Software design >  Why one of my FOR commands is not looping in the text file
Why one of my FOR commands is not looping in the text file

Time:01-24

I don't understand why my first loop is looping only one time and only taking the first line from mp4list-5.txt and if i delete the last one for /f "tokens=3" %%D in ('find/c "outro" %%A') is start working.

Can anyone tell me what I do wrong?

@echo off
setlocal enabledelayedexpansion

<"mp4list-5.txt" (
    for /F "delims=" %%A in (mp3list-5.txt) DO (
        set /p mp4list=
        for /F "UseBackQ tokens=2 delims='" %%B in ("%%A") DO (
            for /f  %%C in ('Find /V /C "" ^< "%%A"') DO (
                for /f "tokens=3" %%D in ('find/c "outro" %%A') do (  

                    set "mp3list=%%A"
                    set "outro=%%D"

                    echo !mp4list! is MP4 list
                    echo !mp3list! Is Mp3 List
                    echo  %%B  is B
                    echo  %%~nB  is FileName
                    echo  %%C  is C
                    echo  %%D  is How mnay times "outro" word exist
 
                    if !outro! GEQ 1 (
                        set "exportname=%%~nB" 
                    ) 
 
                    if !outro! == 0 (
                        if %%C GEQ 2 (
                            set "exportname=!RANDOM!"
                        )
                    )

                    if !outro! == 0 (
                        if %%C == 1 (
                            set "exportname=%%~nB"
                        )
                    )

                    echo !exportname!

                    REM Here the ffmpeg code will be to concatenate the mp3 and mp4 files, then join them.

                )
            )
        )
    )
)

mp4list-5.txt contains

F:\...\...\...\...\....\Videos-1\output-mp4.txt
F:\...\...\...\...\....\Videos-2\output-mp4.txt
F:\...\...\...\...\....\Videos-3\output-mp4.txt
F:\...\...\...\...\....\Videos-4\output-mp4.txt

mp3list-5.txt contains

F:\...\...\...\...\....\Videos-1\output-mp3.txt
F:\...\...\...\...\....\Videos-2\output-mp3.txt
F:\...\...\...\...\....\Videos-3\output-mp3.txt
F:\...\...\...\...\....\Videos-4\output-mp3.txt

CodePudding user response:

I resolved the issue via the standard handles. I changed

3<"mp4list-5.txt" (

and

set /p mp4list= <&3

and final working batch looking like that, Hope will help SO community

@echo off
setlocal enabledelayedexpansion

3<"mp4list-5.txt" (for /F "delims=" %%A in (mp3list-5.txt) DO (   
        for /F "UseBackQ tokens=2 delims='" %%B in ("%%A") DO (
            for /f  %%C in ('Find /V /C "" ^< "%%A"') DO (
                for /f "tokens=3" %%D in ('find /c "outro" "%%A"') do (  

                    set /p mp4list= <&3
                    set "mp3list=%%A"
                    set "outro=%%D"

                    echo !mp4list! is MP4 list
                    echo !mp3list! Is Mp3 List
                    echo  %%B  is B
                    echo  %%~nB  is FileName
                    echo  %%C  is C
                    echo  %%D  is How mnay times "outro" word exist

                    if !outro! GEQ 1 (
                        set "exportname=%%~nB" 
                    ) 
 
                    if !outro! == 0 (
                        if %%C GEQ 2 (
                             set "exportname=!RANDOM!"
                        )
                    )

                    if !outro! == 0 (
                        if %%C == 1 (
                             set "exportname=%%~nB"
                        )
                    )

                    echo !exportname! is EXPORT NAME

                    REM Here the ffmpeg code will be to concatenate the mp3 and mp4 files, then join them.

                )
            )
        )
    )
)
  • Related