sidwelle
asked on
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 ?
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 ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
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
E.g.
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!
Steve
Do dir > test.text. is short for 1>test.text
E.g.
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!
Steve
ASKER
Good Info, Thanks for the help.
np
(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%
Steve