cmd shell copy

I have a batch file that copies some files on the network, but its not behaving the same way with files on network drives as it does on test folders on my local machines:

copy \\Share\file.out + \\Share\*.txt  \\Share\file.out
Del *.txt

what I expect to see is that all the txt files appended to file.out, but what I see is that the contents of file.out is duplicated 1 time in file.out for each time the file runs.  In short file.out is being appended with "file.out + *.txt" not replaced with ?
Who is Participating?
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.

Steve KnightIT ConsultancyCommented:
Personally I tend to use:

type \\server\share\*.txt > newfile.txt

You can also do:

copy \\server\share\*.txt newfile.txt


[ Edit - re-read, to append I'd use TYPE with >> instead, i.e.

TYPE \\server\share\*.txt >> newfile.txt

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
Steve KnightIT ConsultancyCommented:
With what you have I would expect you'd get

(contents of existing file.out)
contents of file1.txt
contents of file2.txt
etc. which is I assume what you are after.

The other way I use if I want a specific order, e.g. date/time is for loop over files and append one by one using output of dir command - change the /od paramter to sort by date+time, name etc.

@echo off
pushd \\server\share
set outfile="file.out"
for /f %%a "tokens=*" %%a in ('dir /b /a-d /od *.txt') do TYPE %%~a >> %outfile%

sidwelleAuthor Commented:
Good solution !

Question: When I watch what it executed, I see the command line was executed with a "1", what does the 1 represent ?

//Batch file
type \\server\share\*.txt >> newfile.txt

//Cmd window
type \\server\share\*.txt  1>> newfile.txt
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Steve KnightIT ConsultancyCommented:
Good q. 1 means standard output or Stdout. 2 means errors and 0 means input.

Do dir > test.text.  is short for 1>test.text


MD xyz 2>nul

Means mske dir xyz and any errors send to nul I.e. they disappear, normal output goes to screen.

Can redirect both to two different files or to same:

Dir > output.text 2> errors.text
Or both to same file... &1 means to redirect errors to stream 1 which is normal output...

Dir > output.text 2>&1

That is why sometimes if you redirect output some things show on screen or miss from the log unless you use above.

That'll do typing on phone... Something dlto do while waiting boy going to sleep!

sidwelleAuthor Commented:
Good Info, Thanks for the help.
Steve KnightIT ConsultancyCommented:
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
Windows Batch

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.