Clubbing of files in DOS

  • Thread starter Thread starter Pal
  • Start date Start date
P

Pal

I want to merge a.txt, b.txt, c.txt, d.txt etc into z.txt
one file. There should be a delimeter (say a $ sign) in
my z.txt for each file I merge into it.

Please help, how should I do this?
 
Pal said:
I want to merge a.txt, b.txt, c.txt, d.txt etc into z.txt
one file. There should be a delimeter (say a $ sign) in
my z.txt for each file I merge into it.

Please help, how should I do this?

type "a.txt" > "z.txt"
echo.$>> "z.txt"
type "b.txt" >> "z.txt"
echo.$>> "z.txt"
type "c.txt" >> "z.txt"
echo.$>> "z.txt"

That'll work either from the command-line or within a batch file.
 
Thanks Paul. I am looking for something more...I want a
procedure(or a batch file) to look into C:\Items\ folder
at a regular interval and merge all available files into
one z.txt file in C:\ folder. The C:\Items\ folder gets
*.txt files from a program where I cannot predict *. It
can be item01.txt and next file item32.txt and so on...


-----Original Message-----
 
Thanks Paul. I am looking for something more...I want a
procedure(or a batch file) to look into C:\Items\ folder
at a regular interval and merge all available files into
one z.txt file in C:\ folder. The C:\Items\ folder gets
*.txt files from a program where I cannot predict *. It
can be item01.txt and next file item32.txt and so on...

=====begin c:\cmd\demo\ConcatenateTextFiles.cmd ====================
1. @echo off
2. for %%a in (c:\Items\*.txt) do (
3. echo/----------%%~fa-------------->>c:\z.txt
4. type "%%~fa">>c:\z.txt
5. echo $>>c:\z.txt
6. )
=====end c:\cmd\demo\ConcatenateTextFiles.cmd ====================
 
What happens to the existing Z.txt, it's could be there, will be, or won't be. Is the order of files merged not important?
 
I think you want something like this:
@echo off
for /f %%c in ('dir /b/o-d c:\Items\*.txt') do (
if %%~nxc equ lastcheck.dummy goto BreakOut
type "%%c" >> "c:\z.txt"
echo.$>> "c:\z.txt"
)
:BreakOut
type NUL> c:\items\lastcheck.dummy

What happens it sorts by date, reverse order the *.txt files in c:\Items and
concatenates their contents to c:\z.txt until it finds
c:\items\lastcheck.dummy which is a marker file you create in the script.
The first time the batch is run the file doesn't exist so all *.txt files
will be added to c:\z.txt and c:\items\lastcheck.dummy will be created. The
next time the batch is run it will stop concatenating TXT files when it hits
the dummy files so only new files will be added to c:\z.txt. The $ character
is used as a separator.
 
I forgot, extensions must be enabled and you should reset DIRCMD

setlocal enableextensions
set DIRCMD=
@echo off
for /f %%c in ('dir /b/o-d c:\Items\*.txt') do (
if %%~nxc equ lastcheck.dummy goto BreakOut
type "%%c" >> "c:\z.txt"
echo.$>> "c:\z.txt"
)
:BreakOut
type NUL> c:\items\lastcheck.dummy
 
Sorry another correction. I'm falling asleep and shouldn't be answering
questions. :) Of course, you run this from the task scheduler every x
minutes as you need.

@echo off
setlocal enableextensions
set DIRCMD=
cd c:\items
for /f %%c in ('dir /b/o-d c:\Items\*.txt') do (
if %%~nxc equ lastcheck.dummy goto BreakOut
type "%%c" >> "c:\z.txt"
echo.$>> "c:\z.txt"
)
:BreakOut
type NUL> c:\items\lastcheck.dummy
 
One more to deal with spaces in the filenames:

@echo off
setlocal enableextensions
set DIRCMD=
cd c:\items
for /f "tokens=*" %%c in ('dir /b/o-d c:\Items\*.txt') do (
if %%~nxc equ lastcheck.dummy goto BreakOut
type "%%c" >> "c:\z.txt"
echo.$>> "c:\z.txt"
)
:BreakOut
type NUL> c:\items\lastcheck.dummy
 
I am not sure if this would meet your need. I have merged files before using the copy command. How about a text file called delim.txt that has a single line of delimiter in it and hit enter key after the single line. Then use copy a.txt+delim.txt+b.txt+delim.txt+c.txt+delim.txt+d.txt. This would merge all files into a.txt with a delimiter after each file. Just make sure that the last line in each file has a carriage return in it (hit the enter key, so the cursor is at the next line)
 
I was a bit concerned at the idea of clubbing a bunch of files as if they
were, well, seals or some other defenceless animal. Then I realized that he
was probably thinking of clubbing in the social sense.

/Al

PS: sorry - end of a long half-week

David said:
I am not sure if this would meet your need. I have merged files before
using the copy command. How about a text file called delim.txt that has a
single line of delimiter in it and hit enter key after the single line. Then
use copy a.txt+delim.txt+b.txt+delim.txt+c.txt+delim.txt+d.txt. This would
merge all files into a.txt with a delimiter after each file. Just make sure
that the last line in each file has a carriage return in it (hit the enter
key, so the cursor is at the next line)
 
In microsoft.public.win2000.cmdprompt.admin Al Dunbar [MS-MVP]
wrote:
I was a bit concerned at the idea of clubbing a bunch of files as
if they were, well, seals or some other defenceless animal. Then I
realized that he was probably thinking of clubbing in the social
sense.
PS: sorry - end of a long half-week

LOL and you are excused. Did the word "concatenate" ever even make
it into the thread? Beat, whip, and club those files until they do
 
To concatenate files under DOS (Win98) works:
c:\>copy file1.txt+file2.txt+file3.txt bigfile.txt
(works only txt files, not other or bin types)
 
In said:
To concatenate files under DOS (Win98) works:
c:\>copy file1.txt+file2.txt+file3.txt bigfile.txt
(works only txt files, not other or bin types)

Cannot recall, but MS DOS 7's COPY command does have the "/b" switch
does it not?

NTx certainly does.
 
Back
Top