Combine Files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Bok
Posts: 3
Joined: 11 Sep 2014 05:58

Combine Files

#1 Post by Bok » 11 Sep 2014 06:33

Hello!
(Using Win 7 64 bit)

I have dozens of "*.pas" files in a single directory.
I want to merge all the "*.pas" files together into one large file called "Combined.txt" in that same directory.
I want a line of astericks "************" to be written to "Combined.txt" between each "*.pas" file.

I have tried DOZENS of variations, but I can't get it to work. I HAVE READ the help files, maybe
I'm just dense.

:::::::::::::::::::::::::::Here is <PSEUDOCODE> for what I want to do :::::::::::::::::::::::::
: :
: For %%x in (*.pas) do (copy %%x /A Combined.txt ; do echo ************ >>%%x) :
: :
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Any help would be greatly appreciated.

TY
Bok

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: New user question

#2 Post by Squashman » 11 Sep 2014 06:44

Code: Select all

@echo off
FOR %%G in (*.pas) do (
   type "%%~G">>combined.txt
   echo ************>>combined.txt
)

Bok
Posts: 3
Joined: 11 Sep 2014 05:58

Re: Combine Files

#3 Post by Bok » 11 Sep 2014 07:39

Thanks so much.I would have never gotten that.
I modified it with a pipe "|". It is less clear to read, but is 2 less lines long.

FOR %%G in (*.pas) do (type "%%~G">> combined.txt | echo ************>>combined.txt)

I used to do a VERY LITTLE bit of batch work way back in Win 3.0 - 3.1. Wow!!! have things changed.
I guess I'll have to find a book that takes me step by step with all the new functionality and
syntax of modern batch.

Thanks Again
Bok

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Combine Files

#4 Post by Squashman » 11 Sep 2014 08:17

I would think you would want to use an ampersand. Not a Pipe.

Bok
Posts: 3
Joined: 11 Sep 2014 05:58

Re: Combine Files

#5 Post by Bok » 11 Sep 2014 08:34

I just put it in and I got lucky- it worked; but, you are correct
I should use the "&". It's been ~20yrs since I've done batch
and I've forgotten so much and so much has changed

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Combine Files

#6 Post by Samir » 22 Sep 2014 15:41

I too started in batch many many moons ago (DOS 3.3). But aside some from new tricks added on all the commands, you can still run a batch file from DOS 3.3 and it works. :)

To me, all the changes are quite welcome as you can do things today that were really hard (if not impossible) to do in the win3.0-3.1 days.

Post Reply