Append log files to similarly named txt files

August 29, 2010 at 11:28:54
Specs: Windows XP
I used a script to extract info from text files and now have a directory full of .txt files each with a corresponding .log file ie if the text file is 123456.txt it has a matching log file 123456.log. I am trying to write a BAT/ VBscript file which when run will go through all the files in the directory and append each log file to the end of each matching text file and save the resultant output files as text files in a new directory. The original text file name should be retained ie if one were 123456.txt then the resultant file after appending should be 123456.txt

I've searched on the net but although there is plenty on appending I couldn't find anything which would do what I need so I would be grateful for any help from anyone out there

Thank you

See More: Append log files to similarly named txt files

Report •

August 30, 2010 at 03:40:53
Try this out, change indir and newdir to the paths to input files and output files resp.

@echo off
setlocal enabledelayedexpansion

pushd indir\||echo Pushd failed - job terminated&&exit /b

for /f "tokens=*" %%1 in ('dir /a-d /b *.txt') do (
    set fil=%%~n1
    if exist "!fil!.log" copy "%%1"+"!fil!.log" "newdir\!fil!.txt">nul


Report •

August 30, 2010 at 09:54:10
You are one ace surfer!!

Your batch file gave me exactly what I needed!

Many, many thanks


Report •

August 30, 2010 at 13:12:25
You're welcome & thanks for coming back to advise us of your success.

Report •
Related Solutions

Ask Question