Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 384
  • Last Modified:

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 ?
  • 4
  • 2
1 Solution
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
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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

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:

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now