How to merge files in correct order using command prompt












2















I have a folder with video segments from a mpeg-dash video.
there is an "init.mp4" file along with 275 segments, i.e. "seg-1.m4s", "seg-2.m4s" and so on. I want to merge them in a single file.
I am using the following command in cmd:
copy /b init.mp4 + seg-*.m4s source.mp4
The above code is merging the files in wrong order. see the merge order



How do I merge the files in the correct order like, 1,2,3...9,10,11..19,20...



Also note that I have tried merging them one by one using a loop. but that is way slower compared to the above code










share|improve this question


















  • 1





    The core problem is that cmd.exe is sorting them as character strings. Is there any way you could get all files named with a three (3) digit value? seg-001.mp4, seg-020.mp4, etc.

    – lit
    Nov 18 '18 at 22:42











  • Thanks for the tip. I am actually using a python script to download these segments. So i can easily save them with whatever name I want. I think this solves my problem. thanks again

    – Rajorshi Roy
    Nov 19 '18 at 11:49











  • If you're already using a Python script, why not use the same script to append each segment to the main file right from the source? That would save having to create an additional script to do the merge.

    – DodgyCodeException
    Nov 19 '18 at 13:41











  • I found the command line option to be faster. Is there any way to merge the files faster using python only?

    – Rajorshi Roy
    Nov 20 '18 at 14:09











  • p.s. I am not creating a separate batch script to merge. I am calling the os.system( ) function in python

    – Rajorshi Roy
    Nov 20 '18 at 14:12
















2















I have a folder with video segments from a mpeg-dash video.
there is an "init.mp4" file along with 275 segments, i.e. "seg-1.m4s", "seg-2.m4s" and so on. I want to merge them in a single file.
I am using the following command in cmd:
copy /b init.mp4 + seg-*.m4s source.mp4
The above code is merging the files in wrong order. see the merge order



How do I merge the files in the correct order like, 1,2,3...9,10,11..19,20...



Also note that I have tried merging them one by one using a loop. but that is way slower compared to the above code










share|improve this question


















  • 1





    The core problem is that cmd.exe is sorting them as character strings. Is there any way you could get all files named with a three (3) digit value? seg-001.mp4, seg-020.mp4, etc.

    – lit
    Nov 18 '18 at 22:42











  • Thanks for the tip. I am actually using a python script to download these segments. So i can easily save them with whatever name I want. I think this solves my problem. thanks again

    – Rajorshi Roy
    Nov 19 '18 at 11:49











  • If you're already using a Python script, why not use the same script to append each segment to the main file right from the source? That would save having to create an additional script to do the merge.

    – DodgyCodeException
    Nov 19 '18 at 13:41











  • I found the command line option to be faster. Is there any way to merge the files faster using python only?

    – Rajorshi Roy
    Nov 20 '18 at 14:09











  • p.s. I am not creating a separate batch script to merge. I am calling the os.system( ) function in python

    – Rajorshi Roy
    Nov 20 '18 at 14:12














2












2








2


1






I have a folder with video segments from a mpeg-dash video.
there is an "init.mp4" file along with 275 segments, i.e. "seg-1.m4s", "seg-2.m4s" and so on. I want to merge them in a single file.
I am using the following command in cmd:
copy /b init.mp4 + seg-*.m4s source.mp4
The above code is merging the files in wrong order. see the merge order



How do I merge the files in the correct order like, 1,2,3...9,10,11..19,20...



Also note that I have tried merging them one by one using a loop. but that is way slower compared to the above code










share|improve this question














I have a folder with video segments from a mpeg-dash video.
there is an "init.mp4" file along with 275 segments, i.e. "seg-1.m4s", "seg-2.m4s" and so on. I want to merge them in a single file.
I am using the following command in cmd:
copy /b init.mp4 + seg-*.m4s source.mp4
The above code is merging the files in wrong order. see the merge order



How do I merge the files in the correct order like, 1,2,3...9,10,11..19,20...



Also note that I have tried merging them one by one using a loop. but that is way slower compared to the above code







batch-file cmd merge concatenation command-prompt






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 18 '18 at 21:59









Rajorshi RoyRajorshi Roy

163




163








  • 1





    The core problem is that cmd.exe is sorting them as character strings. Is there any way you could get all files named with a three (3) digit value? seg-001.mp4, seg-020.mp4, etc.

    – lit
    Nov 18 '18 at 22:42











  • Thanks for the tip. I am actually using a python script to download these segments. So i can easily save them with whatever name I want. I think this solves my problem. thanks again

    – Rajorshi Roy
    Nov 19 '18 at 11:49











  • If you're already using a Python script, why not use the same script to append each segment to the main file right from the source? That would save having to create an additional script to do the merge.

    – DodgyCodeException
    Nov 19 '18 at 13:41











  • I found the command line option to be faster. Is there any way to merge the files faster using python only?

    – Rajorshi Roy
    Nov 20 '18 at 14:09











  • p.s. I am not creating a separate batch script to merge. I am calling the os.system( ) function in python

    – Rajorshi Roy
    Nov 20 '18 at 14:12














  • 1





    The core problem is that cmd.exe is sorting them as character strings. Is there any way you could get all files named with a three (3) digit value? seg-001.mp4, seg-020.mp4, etc.

    – lit
    Nov 18 '18 at 22:42











  • Thanks for the tip. I am actually using a python script to download these segments. So i can easily save them with whatever name I want. I think this solves my problem. thanks again

    – Rajorshi Roy
    Nov 19 '18 at 11:49











  • If you're already using a Python script, why not use the same script to append each segment to the main file right from the source? That would save having to create an additional script to do the merge.

    – DodgyCodeException
    Nov 19 '18 at 13:41











  • I found the command line option to be faster. Is there any way to merge the files faster using python only?

    – Rajorshi Roy
    Nov 20 '18 at 14:09











  • p.s. I am not creating a separate batch script to merge. I am calling the os.system( ) function in python

    – Rajorshi Roy
    Nov 20 '18 at 14:12








1




1





The core problem is that cmd.exe is sorting them as character strings. Is there any way you could get all files named with a three (3) digit value? seg-001.mp4, seg-020.mp4, etc.

– lit
Nov 18 '18 at 22:42





The core problem is that cmd.exe is sorting them as character strings. Is there any way you could get all files named with a three (3) digit value? seg-001.mp4, seg-020.mp4, etc.

– lit
Nov 18 '18 at 22:42













Thanks for the tip. I am actually using a python script to download these segments. So i can easily save them with whatever name I want. I think this solves my problem. thanks again

– Rajorshi Roy
Nov 19 '18 at 11:49





Thanks for the tip. I am actually using a python script to download these segments. So i can easily save them with whatever name I want. I think this solves my problem. thanks again

– Rajorshi Roy
Nov 19 '18 at 11:49













If you're already using a Python script, why not use the same script to append each segment to the main file right from the source? That would save having to create an additional script to do the merge.

– DodgyCodeException
Nov 19 '18 at 13:41





If you're already using a Python script, why not use the same script to append each segment to the main file right from the source? That would save having to create an additional script to do the merge.

– DodgyCodeException
Nov 19 '18 at 13:41













I found the command line option to be faster. Is there any way to merge the files faster using python only?

– Rajorshi Roy
Nov 20 '18 at 14:09





I found the command line option to be faster. Is there any way to merge the files faster using python only?

– Rajorshi Roy
Nov 20 '18 at 14:09













p.s. I am not creating a separate batch script to merge. I am calling the os.system( ) function in python

– Rajorshi Roy
Nov 20 '18 at 14:12





p.s. I am not creating a separate batch script to merge. I am calling the os.system( ) function in python

– Rajorshi Roy
Nov 20 '18 at 14:12












3 Answers
3






active

oldest

votes


















0














so, my english dont help...
but, i think that your need rename files:



 1 -  9 to 001 - 009:
10 - 99 to 010 - 099:


in commandline:



for /l %l in (1 1 9) do ren seg-%l.m4s seg-00%l.m4s
for /l %l in (10 1 99) do ren seg-%l.m4s seg-0%l.m4s


in batch file :



for /l %%l in (1 1 9) do ren seg-%%l.m4s seg-00%%l.m4s
for /l %%l in (10 1 99) do ren seg-%%l.m4s seg-0%%l.m4s


After this, run your code:



copy /b init.mp4 + seg-*.m4s source.mp4 





share|improve this answer





















  • 2





    no, the OP needs to combine those files into one

    – phuclv
    Nov 19 '18 at 3:08











  • @phclv- nOp- need put files in right order first, then merge files.

    – kaputtz
    Nov 19 '18 at 9:52






  • 2





    no. he doesn't need to rename the files. And you only add the merge part after my comment

    – phuclv
    Nov 19 '18 at 10:19



















2














A very simple pure Batch-file solution:



@echo off
setlocal EnableDelayedExpansion

rem Sort file names in numerical order
for /F "tokens=1,2 delims=-." %%a in ('dir /B *.m4s') do (
set /A "num=1000+%%b"
set "file[!num!]=%%a-%%b.m4s"
)

rem Create the ordered list
set "files=init.mp4"
for /F "tokens=2 delims==" %%a in ('set file[') do set "files=!files! + %%a"

rem Do it
copy /B %files% source.mp4





share|improve this answer





















  • 1





    Problem is, if there are enough files, you'll reach the 8k command line length limit.

    – DodgyCodeException
    Nov 19 '18 at 10:12











  • after running this batch script i got source.mp4 of size 1kb

    – Rajorshi Roy
    Nov 19 '18 at 12:54






  • 1





    @DodgyCodeException: With 3 digits, each + seg-123.m4s file name takes 14 chars, so this method may manage a max of 8192/14 = 585 files. The OP specified 275 files, so...

    – Aacini
    Nov 19 '18 at 17:05













  • Good point. But why is the OP getting a resulting file size of only 1 KB? Maybe your first for /f should use a command rather than a file spec?

    – DodgyCodeException
    Nov 19 '18 at 17:14











  • @DodgyCodeException: Ops! You are right! :( Just fixed...

    – Aacini
    Nov 19 '18 at 18:41



















1














This can be done fairly easily. Put this code in a file named mp4match.ps1. The key to this code that the sorting is done on the numeric value in the filename. It is extracted by a regex.



$segments = Get-ChildItem -File -Filter 'seg-*.mps' |
Sort-Object @{Expression={([int]([regex]::match($_.Name, 'seg-(d*).mps')).Groups[1].Value)}} |
ForEach-Object { $_.Name }

'init.mp4 ' + $segments -join ' '


Then, use this batch file to run it. When the COPY command looks correct, remove the ECHO at the beginning of the line.



FOR /F "delims=" %%f IN ('powershell -NoProfile -File .mp4match.ps1') DO (
SET "FILE_LIST=%%f"
)
IF EXIST ".source.mp4" (DEL ".source.mp4")
COPY /Y %FILE_LIST% source.mp4





share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53365884%2fhow-to-merge-files-in-correct-order-using-command-prompt%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    so, my english dont help...
    but, i think that your need rename files:



     1 -  9 to 001 - 009:
    10 - 99 to 010 - 099:


    in commandline:



    for /l %l in (1 1 9) do ren seg-%l.m4s seg-00%l.m4s
    for /l %l in (10 1 99) do ren seg-%l.m4s seg-0%l.m4s


    in batch file :



    for /l %%l in (1 1 9) do ren seg-%%l.m4s seg-00%%l.m4s
    for /l %%l in (10 1 99) do ren seg-%%l.m4s seg-0%%l.m4s


    After this, run your code:



    copy /b init.mp4 + seg-*.m4s source.mp4 





    share|improve this answer





















    • 2





      no, the OP needs to combine those files into one

      – phuclv
      Nov 19 '18 at 3:08











    • @phclv- nOp- need put files in right order first, then merge files.

      – kaputtz
      Nov 19 '18 at 9:52






    • 2





      no. he doesn't need to rename the files. And you only add the merge part after my comment

      – phuclv
      Nov 19 '18 at 10:19
















    0














    so, my english dont help...
    but, i think that your need rename files:



     1 -  9 to 001 - 009:
    10 - 99 to 010 - 099:


    in commandline:



    for /l %l in (1 1 9) do ren seg-%l.m4s seg-00%l.m4s
    for /l %l in (10 1 99) do ren seg-%l.m4s seg-0%l.m4s


    in batch file :



    for /l %%l in (1 1 9) do ren seg-%%l.m4s seg-00%%l.m4s
    for /l %%l in (10 1 99) do ren seg-%%l.m4s seg-0%%l.m4s


    After this, run your code:



    copy /b init.mp4 + seg-*.m4s source.mp4 





    share|improve this answer





















    • 2





      no, the OP needs to combine those files into one

      – phuclv
      Nov 19 '18 at 3:08











    • @phclv- nOp- need put files in right order first, then merge files.

      – kaputtz
      Nov 19 '18 at 9:52






    • 2





      no. he doesn't need to rename the files. And you only add the merge part after my comment

      – phuclv
      Nov 19 '18 at 10:19














    0












    0








    0







    so, my english dont help...
    but, i think that your need rename files:



     1 -  9 to 001 - 009:
    10 - 99 to 010 - 099:


    in commandline:



    for /l %l in (1 1 9) do ren seg-%l.m4s seg-00%l.m4s
    for /l %l in (10 1 99) do ren seg-%l.m4s seg-0%l.m4s


    in batch file :



    for /l %%l in (1 1 9) do ren seg-%%l.m4s seg-00%%l.m4s
    for /l %%l in (10 1 99) do ren seg-%%l.m4s seg-0%%l.m4s


    After this, run your code:



    copy /b init.mp4 + seg-*.m4s source.mp4 





    share|improve this answer















    so, my english dont help...
    but, i think that your need rename files:



     1 -  9 to 001 - 009:
    10 - 99 to 010 - 099:


    in commandline:



    for /l %l in (1 1 9) do ren seg-%l.m4s seg-00%l.m4s
    for /l %l in (10 1 99) do ren seg-%l.m4s seg-0%l.m4s


    in batch file :



    for /l %%l in (1 1 9) do ren seg-%%l.m4s seg-00%%l.m4s
    for /l %%l in (10 1 99) do ren seg-%%l.m4s seg-0%%l.m4s


    After this, run your code:



    copy /b init.mp4 + seg-*.m4s source.mp4 






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jan 16 at 14:34

























    answered Nov 19 '18 at 0:01









    kaputtzkaputtz

    198312




    198312








    • 2





      no, the OP needs to combine those files into one

      – phuclv
      Nov 19 '18 at 3:08











    • @phclv- nOp- need put files in right order first, then merge files.

      – kaputtz
      Nov 19 '18 at 9:52






    • 2





      no. he doesn't need to rename the files. And you only add the merge part after my comment

      – phuclv
      Nov 19 '18 at 10:19














    • 2





      no, the OP needs to combine those files into one

      – phuclv
      Nov 19 '18 at 3:08











    • @phclv- nOp- need put files in right order first, then merge files.

      – kaputtz
      Nov 19 '18 at 9:52






    • 2





      no. he doesn't need to rename the files. And you only add the merge part after my comment

      – phuclv
      Nov 19 '18 at 10:19








    2




    2





    no, the OP needs to combine those files into one

    – phuclv
    Nov 19 '18 at 3:08





    no, the OP needs to combine those files into one

    – phuclv
    Nov 19 '18 at 3:08













    @phclv- nOp- need put files in right order first, then merge files.

    – kaputtz
    Nov 19 '18 at 9:52





    @phclv- nOp- need put files in right order first, then merge files.

    – kaputtz
    Nov 19 '18 at 9:52




    2




    2





    no. he doesn't need to rename the files. And you only add the merge part after my comment

    – phuclv
    Nov 19 '18 at 10:19





    no. he doesn't need to rename the files. And you only add the merge part after my comment

    – phuclv
    Nov 19 '18 at 10:19













    2














    A very simple pure Batch-file solution:



    @echo off
    setlocal EnableDelayedExpansion

    rem Sort file names in numerical order
    for /F "tokens=1,2 delims=-." %%a in ('dir /B *.m4s') do (
    set /A "num=1000+%%b"
    set "file[!num!]=%%a-%%b.m4s"
    )

    rem Create the ordered list
    set "files=init.mp4"
    for /F "tokens=2 delims==" %%a in ('set file[') do set "files=!files! + %%a"

    rem Do it
    copy /B %files% source.mp4





    share|improve this answer





















    • 1





      Problem is, if there are enough files, you'll reach the 8k command line length limit.

      – DodgyCodeException
      Nov 19 '18 at 10:12











    • after running this batch script i got source.mp4 of size 1kb

      – Rajorshi Roy
      Nov 19 '18 at 12:54






    • 1





      @DodgyCodeException: With 3 digits, each + seg-123.m4s file name takes 14 chars, so this method may manage a max of 8192/14 = 585 files. The OP specified 275 files, so...

      – Aacini
      Nov 19 '18 at 17:05













    • Good point. But why is the OP getting a resulting file size of only 1 KB? Maybe your first for /f should use a command rather than a file spec?

      – DodgyCodeException
      Nov 19 '18 at 17:14











    • @DodgyCodeException: Ops! You are right! :( Just fixed...

      – Aacini
      Nov 19 '18 at 18:41
















    2














    A very simple pure Batch-file solution:



    @echo off
    setlocal EnableDelayedExpansion

    rem Sort file names in numerical order
    for /F "tokens=1,2 delims=-." %%a in ('dir /B *.m4s') do (
    set /A "num=1000+%%b"
    set "file[!num!]=%%a-%%b.m4s"
    )

    rem Create the ordered list
    set "files=init.mp4"
    for /F "tokens=2 delims==" %%a in ('set file[') do set "files=!files! + %%a"

    rem Do it
    copy /B %files% source.mp4





    share|improve this answer





















    • 1





      Problem is, if there are enough files, you'll reach the 8k command line length limit.

      – DodgyCodeException
      Nov 19 '18 at 10:12











    • after running this batch script i got source.mp4 of size 1kb

      – Rajorshi Roy
      Nov 19 '18 at 12:54






    • 1





      @DodgyCodeException: With 3 digits, each + seg-123.m4s file name takes 14 chars, so this method may manage a max of 8192/14 = 585 files. The OP specified 275 files, so...

      – Aacini
      Nov 19 '18 at 17:05













    • Good point. But why is the OP getting a resulting file size of only 1 KB? Maybe your first for /f should use a command rather than a file spec?

      – DodgyCodeException
      Nov 19 '18 at 17:14











    • @DodgyCodeException: Ops! You are right! :( Just fixed...

      – Aacini
      Nov 19 '18 at 18:41














    2












    2








    2







    A very simple pure Batch-file solution:



    @echo off
    setlocal EnableDelayedExpansion

    rem Sort file names in numerical order
    for /F "tokens=1,2 delims=-." %%a in ('dir /B *.m4s') do (
    set /A "num=1000+%%b"
    set "file[!num!]=%%a-%%b.m4s"
    )

    rem Create the ordered list
    set "files=init.mp4"
    for /F "tokens=2 delims==" %%a in ('set file[') do set "files=!files! + %%a"

    rem Do it
    copy /B %files% source.mp4





    share|improve this answer















    A very simple pure Batch-file solution:



    @echo off
    setlocal EnableDelayedExpansion

    rem Sort file names in numerical order
    for /F "tokens=1,2 delims=-." %%a in ('dir /B *.m4s') do (
    set /A "num=1000+%%b"
    set "file[!num!]=%%a-%%b.m4s"
    )

    rem Create the ordered list
    set "files=init.mp4"
    for /F "tokens=2 delims==" %%a in ('set file[') do set "files=!files! + %%a"

    rem Do it
    copy /B %files% source.mp4






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 19 '18 at 18:40

























    answered Nov 19 '18 at 4:15









    AaciniAacini

    51.3k75274




    51.3k75274








    • 1





      Problem is, if there are enough files, you'll reach the 8k command line length limit.

      – DodgyCodeException
      Nov 19 '18 at 10:12











    • after running this batch script i got source.mp4 of size 1kb

      – Rajorshi Roy
      Nov 19 '18 at 12:54






    • 1





      @DodgyCodeException: With 3 digits, each + seg-123.m4s file name takes 14 chars, so this method may manage a max of 8192/14 = 585 files. The OP specified 275 files, so...

      – Aacini
      Nov 19 '18 at 17:05













    • Good point. But why is the OP getting a resulting file size of only 1 KB? Maybe your first for /f should use a command rather than a file spec?

      – DodgyCodeException
      Nov 19 '18 at 17:14











    • @DodgyCodeException: Ops! You are right! :( Just fixed...

      – Aacini
      Nov 19 '18 at 18:41














    • 1





      Problem is, if there are enough files, you'll reach the 8k command line length limit.

      – DodgyCodeException
      Nov 19 '18 at 10:12











    • after running this batch script i got source.mp4 of size 1kb

      – Rajorshi Roy
      Nov 19 '18 at 12:54






    • 1





      @DodgyCodeException: With 3 digits, each + seg-123.m4s file name takes 14 chars, so this method may manage a max of 8192/14 = 585 files. The OP specified 275 files, so...

      – Aacini
      Nov 19 '18 at 17:05













    • Good point. But why is the OP getting a resulting file size of only 1 KB? Maybe your first for /f should use a command rather than a file spec?

      – DodgyCodeException
      Nov 19 '18 at 17:14











    • @DodgyCodeException: Ops! You are right! :( Just fixed...

      – Aacini
      Nov 19 '18 at 18:41








    1




    1





    Problem is, if there are enough files, you'll reach the 8k command line length limit.

    – DodgyCodeException
    Nov 19 '18 at 10:12





    Problem is, if there are enough files, you'll reach the 8k command line length limit.

    – DodgyCodeException
    Nov 19 '18 at 10:12













    after running this batch script i got source.mp4 of size 1kb

    – Rajorshi Roy
    Nov 19 '18 at 12:54





    after running this batch script i got source.mp4 of size 1kb

    – Rajorshi Roy
    Nov 19 '18 at 12:54




    1




    1





    @DodgyCodeException: With 3 digits, each + seg-123.m4s file name takes 14 chars, so this method may manage a max of 8192/14 = 585 files. The OP specified 275 files, so...

    – Aacini
    Nov 19 '18 at 17:05







    @DodgyCodeException: With 3 digits, each + seg-123.m4s file name takes 14 chars, so this method may manage a max of 8192/14 = 585 files. The OP specified 275 files, so...

    – Aacini
    Nov 19 '18 at 17:05















    Good point. But why is the OP getting a resulting file size of only 1 KB? Maybe your first for /f should use a command rather than a file spec?

    – DodgyCodeException
    Nov 19 '18 at 17:14





    Good point. But why is the OP getting a resulting file size of only 1 KB? Maybe your first for /f should use a command rather than a file spec?

    – DodgyCodeException
    Nov 19 '18 at 17:14













    @DodgyCodeException: Ops! You are right! :( Just fixed...

    – Aacini
    Nov 19 '18 at 18:41





    @DodgyCodeException: Ops! You are right! :( Just fixed...

    – Aacini
    Nov 19 '18 at 18:41











    1














    This can be done fairly easily. Put this code in a file named mp4match.ps1. The key to this code that the sorting is done on the numeric value in the filename. It is extracted by a regex.



    $segments = Get-ChildItem -File -Filter 'seg-*.mps' |
    Sort-Object @{Expression={([int]([regex]::match($_.Name, 'seg-(d*).mps')).Groups[1].Value)}} |
    ForEach-Object { $_.Name }

    'init.mp4 ' + $segments -join ' '


    Then, use this batch file to run it. When the COPY command looks correct, remove the ECHO at the beginning of the line.



    FOR /F "delims=" %%f IN ('powershell -NoProfile -File .mp4match.ps1') DO (
    SET "FILE_LIST=%%f"
    )
    IF EXIST ".source.mp4" (DEL ".source.mp4")
    COPY /Y %FILE_LIST% source.mp4





    share|improve this answer






























      1














      This can be done fairly easily. Put this code in a file named mp4match.ps1. The key to this code that the sorting is done on the numeric value in the filename. It is extracted by a regex.



      $segments = Get-ChildItem -File -Filter 'seg-*.mps' |
      Sort-Object @{Expression={([int]([regex]::match($_.Name, 'seg-(d*).mps')).Groups[1].Value)}} |
      ForEach-Object { $_.Name }

      'init.mp4 ' + $segments -join ' '


      Then, use this batch file to run it. When the COPY command looks correct, remove the ECHO at the beginning of the line.



      FOR /F "delims=" %%f IN ('powershell -NoProfile -File .mp4match.ps1') DO (
      SET "FILE_LIST=%%f"
      )
      IF EXIST ".source.mp4" (DEL ".source.mp4")
      COPY /Y %FILE_LIST% source.mp4





      share|improve this answer




























        1












        1








        1







        This can be done fairly easily. Put this code in a file named mp4match.ps1. The key to this code that the sorting is done on the numeric value in the filename. It is extracted by a regex.



        $segments = Get-ChildItem -File -Filter 'seg-*.mps' |
        Sort-Object @{Expression={([int]([regex]::match($_.Name, 'seg-(d*).mps')).Groups[1].Value)}} |
        ForEach-Object { $_.Name }

        'init.mp4 ' + $segments -join ' '


        Then, use this batch file to run it. When the COPY command looks correct, remove the ECHO at the beginning of the line.



        FOR /F "delims=" %%f IN ('powershell -NoProfile -File .mp4match.ps1') DO (
        SET "FILE_LIST=%%f"
        )
        IF EXIST ".source.mp4" (DEL ".source.mp4")
        COPY /Y %FILE_LIST% source.mp4





        share|improve this answer















        This can be done fairly easily. Put this code in a file named mp4match.ps1. The key to this code that the sorting is done on the numeric value in the filename. It is extracted by a regex.



        $segments = Get-ChildItem -File -Filter 'seg-*.mps' |
        Sort-Object @{Expression={([int]([regex]::match($_.Name, 'seg-(d*).mps')).Groups[1].Value)}} |
        ForEach-Object { $_.Name }

        'init.mp4 ' + $segments -join ' '


        Then, use this batch file to run it. When the COPY command looks correct, remove the ECHO at the beginning of the line.



        FOR /F "delims=" %%f IN ('powershell -NoProfile -File .mp4match.ps1') DO (
        SET "FILE_LIST=%%f"
        )
        IF EXIST ".source.mp4" (DEL ".source.mp4")
        COPY /Y %FILE_LIST% source.mp4






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 19 '18 at 3:02

























        answered Nov 19 '18 at 1:38









        litlit

        5,57743052




        5,57743052






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53365884%2fhow-to-merge-files-in-correct-order-using-command-prompt%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Guess what letter conforming each word

            Port of Spain

            Run scheduled task as local user group (not BUILTIN)