Batch file: How to play with loops and creating new directories

Viewed 40

I can't find the solution. I made the directory to be generated, with the approach that if it exists, create another one with -1, -2 ... added to the name of the directory. But I can't get it to continue exporting the loop from MP4list and export it differently in the other directories.

Below I will explain the batch file in great detail, maybe someone has a solution how to approach the situation:

First try

@echo off
setlocal enabledelayedexpansion
set "musicdir=MUZICA-wav-mp3"  
set "exportfoldername=Canal"
set "exportdir=Export\%exportfoldername%
set "videodir=Video-15-sec"  

set n=0
md "%exportdir%"||call :a %n%


<"mp4list.txt" (
    for %%A in ("%musicdir%\*") DO (
        set /p mp4list=
        ffmpeg -f concat -safe 0 -i "!mp4list!" -c copy mergedmp4.mp4
        ffmpeg -i mergedmp4.mp4 -i "%%A" -map 0:v -map 1:a -vcodec copy -c:a aac -b:a 320k "%exportdir%-%n%\%%~nA.mp4"
        del mergedmp4.mp4"
    )
)   

exit
:a
set /a n+=1
md "%exportdir%-%n%"||goto a
exit /b

For my second try I used for /f "skip=

@echo off
setlocal enabledelayedexpansion
set "musicdir=D:\MONTAJ VIDEO\video-simplu\MUZICA-wav-mp3"  

 

set "exportdir=D:\MONTAJ VIDEO\video-simplu\Export\canal-1
set "exportdir2=D:\MONTAJ VIDEO\video-simplu\Export\canal-2
set "exportdir3=D:\MONTAJ VIDEO\video-simplu\Export\canal-3
set "videodir=D:\LUCRU-VIDEO\Video-15-sec"  



rem ==============  Canal-1

for /f "skip=1" %%G IN (mp4list.txt) DO if not defined line set "line=%%G"

for %%A in ("%musicdir%\*") DO (
        mkdir "%exportdir%" 
        
        echo %line%
        ffmpeg -f concat -safe 0 -i "%line%" -c copy mergedmp4.mp4
    ffmpeg -i mergedmp4.mp4 -i "%%A" -map 0:v -map 1:a -vcodec copy -c:a aac -b:a 320k "%exportdir%\%%~nA.mp4"
        del mergedmp4.mp4"
    )


rem ==============  Canal-2
for /f "skip=3" %%G IN (mp4list.txt) DO if not defined line set "line2=%%G"
 

for %%A in ("%musicdir%\*") DO (
        mkdir "%exportdir2%"
        echo %line2%
        ffmpeg -f concat -safe 0 -i "%line2%" -c copy mergedmp4.mp4
    ffmpeg -i mergedmp4.mp4 -i "%%A" -map 0:v -map 1:a -vcodec copy -c:a aac -b:a 320k "%exportdir2%\%%~nA.mp4"
        del mergedmp4.mp4"
    )


rem ==============  Canal-3
for /f "skip=5" %%G IN (mp4list.txt) DO if not defined line set "line3=%%G"

for %%A in ("%musicdir%\*") DO (
        mkdir "%exportdir3%"
       echo %line3%
        ffmpeg -f concat -safe 0 -i "%line3%" -c copy mergedmp4.mp4
    ffmpeg -i mergedmp4.mp4 -i "%%A" -map 0:v -map 1:a -vcodec copy -c:a aac -b:a 320k "%exportdir3%\%%~nA.mp4"
        del mergedmp4.mp4"
    )

I really don't know in what direction to go...

Let's say I have 5 songs in the directory musicdir and 100 lines with different .mp4 paths in mp4list.txt , 100 directories with the same 5 songs in each directory should be created. Canal-1, Canal-2 ... Canal-100

When all songs in musicdir are exported in Canal-1 the loop will start again with the same songs from musicdir, with the difference that .mp4 videos will be exported in the next folder Canal-2 and so on.

but it is very important that the loop continues in the file mp4list.txtand continue where it left off in the previous directory in order not to repeat the same mp4 files

mp4list.txt contains the path's of mp4 files, all are unique

even if from musicdir it will start from the beginning with exporting mp4 files in a new directory, in mp4list.txt it will continue where it left off in the previous directory

Batch will finish when all lines in mp4list.txt are finished.

mp4list.txt is like this

output.txt
output1.txt
...
output100.txt

and every output.txt have the path to mp4 file. like this

file '1.mp4'
file '2.mp4'
file '3.mp4'
file '4.mp4'

thank you for your help

0 Answers
Related