Announcement

Collapse
No announcement yet.

Merging files .bat

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Merging files .bat

    I have a file called header.txt I want this file to be prepended (first line) to all *.txt files in the same directory.

    How could I achieve this?

    Thanks in advance,
    Joe

  • #2
    Re: Merging files .bat

    You can use copy /b to merge files.

    sample,
    Code:
    @echo off
    
    Set "headerfile=c:\scripts\header.txt"
    
    copy /y "%headerfile%" "%temp%.\*._$$"
    call:wrkfile "%headerfile%" _$$
    
    
    pushD "c:\test\data folder" &&(
    
       for %%* in ("*.txt") do (
         copy /b "%temp%.\%wrkfile%" + "%%*"
         Move /y "%wrkfile%" "%%*")
    )
    popD 
    del "%temp%.\%wrkfile%"
    
    goto:EOF
    :wrkfile
    Set "wrkfile=%~n1.%~2"
    exit /b 0
    \Rems
    Last edited by Rems; 19th September 2010, 11:55.

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment

    Working...
    X