VbScript to copy multiple files in a folder in to one text file but copy each file to a new line

I am trying to copy multiple files in a folder to one text file but want to append each file as a new line
tvaeAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lee W, MVPTechnology and Business Process AdvisorCommented:
So it's not entirely clear what you have and what you want - If you want to COMBINE multiple text files into one text, then why must it be in vbscript?

A single command line could do it...
for /f "tokens=* %a in ('dir /b *.txt') do type %a>>combinedfiles.text
tvaeAuthor Commented:
Either a vbscript or command line will do.

the sample you gave me is for a command line but how can I specify the dir? do I replace the dir ?
Lee W, MVPTechnology and Business Process AdvisorCommented:
Give me an example of what you have
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

tvaeAuthor Commented:
I have a command line right now that just

type \inbox\*.* >> Receive.txt

it copies the files but I want to copy the file with new lines

meaning if I have 2 files
it will write to my Receive.txt
file data 1.....
file data2.....

right now with the type command it gives me this result
file data 1.......file data 2......
Lee W, MVPTechnology and Business Process AdvisorCommented:
Ok - save this as a batch file:
@echo off
for /f "tokens=* %%a in ('dir /b *.txt') do (
   type %%a>>combinedfiles.text
   echo. >>combinedfiles.text
)

Open in new window

(NOTE - in a batch file, %a changes to %%a)
tvaeAuthor Commented:
Lee,

how will it know the dir?
@echo off
for /f "tokens=* %%a in ('dir /b *.txt') do (
   type %%a>>combinedfiles.text
   echo. >>combinedfiles.text
Lee W, MVPTechnology and Business Process AdvisorCommented:
You run it in the directory you have the files.
tvaeAuthor Commented:
I cant run it in that folder and I am using *.* as the filenames can vary

can I do it this way?
for /f "tokens=* %%a in ('\inbox\*.*  /b' ) do (
    type %%a>>combinedfiles.text
    echo. >>combinedfiles.text
Lee W, MVPTechnology and Business Process AdvisorCommented:
This is why I asked for an example - if I could clearly see what you need...
tvaeAuthor Commented:
This is the file I will copy to one text file and it can be multiple files in the folder.
IN201305061600135823032.txt
Lee W, MVPTechnology and Business Process AdvisorCommented:
Ok, let me try to start over, I'm not worried about file content.  I am concerned about how you have these on the disk.  WHERE they are.  Are in the c:\MyFiles?  Are they in several sub folders?  Are they all .txt files.

echo. displays a blank line.
>>  redirects the output AND APPENDS to a file name (and optional path) specified.
type sends the specified file to the screen.

So echo. >> combinedfile.txt puts a blank line (carriage return / line feed) in the combinedfile.txt
So type filename.txt >> combinedfile.txt will "display" the filename.txt file but instead of showing it on screen it outputs to the file "combinedfile.txt" APPENDING the filename.txt to the combinedfile.txt file.
If you need a blank line, make it TWO steps:

thus
echo. >> combinedfile.txt
type filename.txt >> combinedfile.txt

Puts a line followed by the filename.txt in the combinedfile.txt.
Bill PrewIT / Software Engineering ConsultantCommented:
Give this a try, should get the job done.  Adjust paths in the SET statements near the top.

@echo off

set BaseDir=B:\EE\EE28807419\inbox
set OutFile=B:\EE\EE28807419\received.txt

(
  for %%a in ("%BaseDir%\*.*") do (
    type "%%~a"
    echo.
    echo.
  )
)>"%OutFile%"

Open in new window

~bp

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.