Vagelism22678
Vagelism22678

Reputation: 47

Concatenation of files.

What is the best way to concatenate a series of multiple files in windows environment command prompt? Copy /b file1.mpg+file2.mpg newfile.mpg

Works great, but I need a automated batch process to join handrends of them.

Thank you.

Upvotes: 0

Views: 78

Answers (2)

SomethingDark
SomethingDark

Reputation: 14370

If you don't want to left-pad the numbers in the filenames with zeroes, you can count the number of files in the directory and then user a for /L loop to iterate over each one.

@echo off

:: Change this to wherever your files are located
set "source_dir=%userprofile%\Desktop\test_files"

:: Put the output file in the same directory as this script
set "target_file=%~dp0output.mpg"
echo(>%target_file%

:: Count the number of files in the source directory by searching the output
:: of dir /b for the number of lines that are not blank
for /F %%A in ('dir /b %source_dir% ^| find /c /v ""') do set "file_count=%%A"

:: Iterate over the entire set of files and merge them in order
for /L %%A in (1,1,%file_count%) do copy /b %target_file%+%source_dir%\file%%A.mpg %target_file%

Upvotes: 1

marosu
marosu

Reputation: 26

You can use a wildcard. copy /b *.mpg newfile.mpg

Upvotes: 1

Related Questions