PC Review


Reply
Thread Tools Rate Thread

Copy multiple files into a single file - xcopy?

 
 
=?Utf-8?B?Sm9ybnlP?=
Guest
Posts: n/a
 
      14th Mar 2007
I want to copy multiple text files into a single text file without having to
have all of the text files in one folder. The problem is that many of the
text files have the same name, so I want them to remain in separate
sub-folders. If the text files are all in the same folder, I know I can just
use the DOS command: copy *.txt file.txt.

I tried using xcopy *.txt C:\file.txt /s, hoping that all the text files in
the subfolders of my working directory would all get copied into file
C:\file.txt. But instead, it just overwrote file.txt a couple of thousand
times rather than combining all the files into one big text file.

Any advice?
 
Reply With Quote
 
 
 
 
Bob I
Guest
Posts: n/a
 
      14th Mar 2007
Direct quote from Windows Help for Xcopy.

"Appending files
To append files, specify a single file for destination, but multiple
files for source (that is, by using wildcards or file1+file2+file3 format)."

My interpretation of past experience.
You need at least one + in there as I recall. Also you will want the
destination NOT in the same path as the source files.

JornyO wrote:

> I want to copy multiple text files into a single text file without having to
> have all of the text files in one folder. The problem is that many of the
> text files have the same name, so I want them to remain in separate
> sub-folders. If the text files are all in the same folder, I know I can just
> use the DOS command: copy *.txt file.txt.
>
> I tried using xcopy *.txt C:\file.txt /s, hoping that all the text files in
> the subfolders of my working directory would all get copied into file
> C:\file.txt. But instead, it just overwrote file.txt a couple of thousand
> times rather than combining all the files into one big text file.
>
> Any advice?


 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a
 
      14th Mar 2007

"JornyO" <(E-Mail Removed)> wrote in message
news:C9E39C43-2C4D-44D5-B182-(E-Mail Removed)...
> I want to copy multiple text files into a single text file without having

to
> have all of the text files in one folder. The problem is that many of the
> text files have the same name, so I want them to remain in separate
> sub-folders. If the text files are all in the same folder, I know I can

just
> use the DOS command: copy *.txt file.txt.
>
> I tried using xcopy *.txt C:\file.txt /s, hoping that all the text files

in
> the subfolders of my working directory would all get copied into file
> C:\file.txt. But instead, it just overwrote file.txt a couple of thousand
> times rather than combining all the files into one big text file.
>
> Any advice?


I think an example would go a long way towards describing
your exact requirements accurately.


 
Reply With Quote
 
=?Utf-8?B?Sm9ybnlP?=
Guest
Posts: n/a
 
      15th Mar 2007
What I wrote earlier basically was an example of what I am trying to do. In
the folder C:\Data there are multiple sub-folders (\010101, \010102, \010103,
etc...) that each contain several text files. I can't copy all of the text
files from these subfolders into a single folder (in order to use "copy" in
command prompt) because there are files in the different subfolders with the
same name. What I was trying to do with the xcopy command was copy all of
the contents of the .txt files in the subfolders into a single .txt file
located in C:\.

The command I tried was: xcopy *.txt C:\file.txt /s

This command did in fact copy each text file from the subfolders, but rather
than appending them all into the same file, it just overwrote C:\file.txt
each time it copied one of the text files from one of the subfolders. For
some reason, using the simple command "copy *.txt file.txt" works fine if all
of the source text files are in the same folder. But as I said, I want to
get text files from the subfolders and have them all combined into a single
text file. Thanks for your time so far! The help is greatly appreciated.

"Pegasus (MVP)" wrote:

>
> "JornyO" <(E-Mail Removed)> wrote in message
> news:C9E39C43-2C4D-44D5-B182-(E-Mail Removed)...
> > I want to copy multiple text files into a single text file without having

> to
> > have all of the text files in one folder. The problem is that many of the
> > text files have the same name, so I want them to remain in separate
> > sub-folders. If the text files are all in the same folder, I know I can

> just
> > use the DOS command: copy *.txt file.txt.
> >
> > I tried using xcopy *.txt C:\file.txt /s, hoping that all the text files

> in
> > the subfolders of my working directory would all get copied into file
> > C:\file.txt. But instead, it just overwrote file.txt a couple of thousand
> > times rather than combining all the files into one big text file.
> >
> > Any advice?

>
> I think an example would go a long way towards describing
> your exact requirements accurately.
>
>
>

 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a
 
      15th Mar 2007
Try this batch file:

@echo off
set HomeFolder=c:\temp

Echo Snapshot taken on %date% at %time:~0,5% > c:\Collect.txt
call :Sub %HomeFolder%
for /F "tokens=*" %%* in ('dir /s /b /ad') do call :Sub %%*
notepad c:\Collect.txt
goto :eof

:Sub
pushd "%*"
if exist *.txt (
echo. >> c:\Collect.txt
echo Folder=%* >> C:\Collect.txt
echo ==================== >> c:\Collect.txt
for %%b in (*.txt) do (
echo %%b >> c:\Collect.txt
type "%%b" >> c:\Collect.txt
)
)
popd

Make sure to copy & paste it rather than retyping it.


"JornyO" <(E-Mail Removed)> wrote in message
news:E86FF8C1-77E1-4671-B147-(E-Mail Removed)...
> What I wrote earlier basically was an example of what I am trying to do.

In
> the folder C:\Data there are multiple sub-folders (\010101, \010102,

\010103,
> etc...) that each contain several text files. I can't copy all of the

text
> files from these subfolders into a single folder (in order to use "copy"

in
> command prompt) because there are files in the different subfolders with

the
> same name. What I was trying to do with the xcopy command was copy all of
> the contents of the .txt files in the subfolders into a single .txt file
> located in C:\.
>
> The command I tried was: xcopy *.txt C:\file.txt /s
>
> This command did in fact copy each text file from the subfolders, but

rather
> than appending them all into the same file, it just overwrote C:\file.txt
> each time it copied one of the text files from one of the subfolders. For
> some reason, using the simple command "copy *.txt file.txt" works fine if

all
> of the source text files are in the same folder. But as I said, I want to
> get text files from the subfolders and have them all combined into a

single
> text file. Thanks for your time so far! The help is greatly appreciated.
>
> "Pegasus (MVP)" wrote:
>
> >
> > "JornyO" <(E-Mail Removed)> wrote in message
> > news:C9E39C43-2C4D-44D5-B182-(E-Mail Removed)...
> > > I want to copy multiple text files into a single text file without

having
> > to
> > > have all of the text files in one folder. The problem is that many of

the
> > > text files have the same name, so I want them to remain in separate
> > > sub-folders. If the text files are all in the same folder, I know I

can
> > just
> > > use the DOS command: copy *.txt file.txt.
> > >
> > > I tried using xcopy *.txt C:\file.txt /s, hoping that all the text

files
> > in
> > > the subfolders of my working directory would all get copied into file
> > > C:\file.txt. But instead, it just overwrote file.txt a couple of

thousand
> > > times rather than combining all the files into one big text file.
> > >
> > > Any advice?

> >
> > I think an example would go a long way towards describing
> > your exact requirements accurately.
> >
> >
> >



 
Reply With Quote
 
=?Utf-8?B?Sm9ybnlP?=
Guest
Posts: n/a
 
      15th Mar 2007
I tried the code you suggested by copying and pasting it into a text file and
then changing the extension to .bat. I tried running it twice, once by
double-clicking on the Batch file icon, and once from Command Prompt. Both
times I got the same result: a 1KB file called Collect.txt in C:\ with a
single line of text that says: "Snapshot taken on 03/15/2007 at 9:00" That
batch file was in the parent folder whose subfolders contain the text files I
want copied into a single file.

Did I miss something? Perhaps my limited knowledge of coding and scripting
is making blind to something that ought to be obvious.



"Pegasus (MVP)" wrote:

@echo off
set HomeFolder=c:\temp

Echo Snapshot taken on %date% at %time:~0,5% > c:\Collect.txt
call :Sub %HomeFolder%
for /F "tokens=*" %%* in ('dir /s /b /ad') do call :Sub %%*
notepad c:\Collect.txt
goto :eof

:Sub
pushd "%*"
if exist *.txt (
echo. >> c:\Collect.txt
echo Folder=%* >> C:\Collect.txt
echo ==================== >> c:\Collect.txt
for %%b in (*.txt) do (
echo %%b >> c:\Collect.txt
type "%%b" >> c:\Collect.txt
)
)
popd

 
Reply With Quote
 
Lem
Guest
Posts: n/a
 
      15th Mar 2007
JornyO wrote:
> I tried the code you suggested by copying and pasting it into a text file and
> then changing the extension to .bat. I tried running it twice, once by
> double-clicking on the Batch file icon, and once from Command Prompt. Both
> times I got the same result: a 1KB file called Collect.txt in C:\ with a
> single line of text that says: "Snapshot taken on 03/15/2007 at 9:00" That
> batch file was in the parent folder whose subfolders contain the text files I
> want copied into a single file.
>
> Did I miss something? Perhaps my limited knowledge of coding and scripting
> is making blind to something that ought to be obvious.
>
>
>
> "Pegasus (MVP)" wrote:
>
> @echo off
> set HomeFolder=c:\temp
>
> Echo Snapshot taken on %date% at %time:~0,5% > c:\Collect.txt
> call :Sub %HomeFolder%
> for /F "tokens=*" %%* in ('dir /s /b /ad') do call :Sub %%*
> notepad c:\Collect.txt
> goto :eof
>
> :Sub
> pushd "%*"
> if exist *.txt (
> echo. >> c:\Collect.txt
> echo Folder=%* >> C:\Collect.txt
> echo ==================== >> c:\Collect.txt
> for %%b in (*.txt) do (
> echo %%b >> c:\Collect.txt
> type "%%b" >> c:\Collect.txt
> )
> )
> popd
>


While you're waiting for Pegasus to explain the esoterica of
command-line programming, try editing the second line of your batch file
to read:

set HomeFolder=c:\Data

(assuming that C:\Data is parent folder whose subfolders contain the
text files you want copied into a single file; otherwise, use the
correct folder name)

--
Lem MS MVP -- Networking

To the moon and back with 64 Kbits of RAM and 512 Kbits of ROM.
http://en.wikipedia.org/wiki/Apollo_Guidance_Computer
 
Reply With Quote
 
Seahawk60B
Guest
Posts: n/a
 
      15th Mar 2007
On Mar 14, 8:39 pm, JornyO <Jor...@discussions.microsoft.com> wrote:
> What I wrote earlier basically was an example of what I am trying to do. In
> the folder C:\Data there are multiple sub-folders (\010101, \010102, \010103,
> etc...) that each contain several text files. I can't copy all of the text
> files from these subfolders into a single folder (in order to use "copy" in
> command prompt) because there are files in the different subfolders with the
> same name. What I was trying to do with the xcopy command was copy all of
> the contents of the .txt files in the subfolders into a single .txt file
> located in C:\.
>
> The command I tried was: xcopy *.txt C:\file.txt /s
>
> This command did in fact copy each text file from the subfolders, but rather
> than appending them all into the same file, it just overwrote C:\file.txt
> each time it copied one of the text files from one of the subfolders. For
> some reason, using the simple command "copy *.txt file.txt" works fine if all
> of the source text files are in the same folder. But as I said, I want to
> get text files from the subfolders and have them all combined into a single
> text file. Thanks for your time so far! The help is greatly appreciated.
>
> "Pegasus (MVP)" wrote:
>
> > "JornyO" <Jor...@discussions.microsoft.com> wrote in message
> >news:C9E39C43-2C4D-44D5-B182-(E-Mail Removed)...
> > > I want to copy multiple text files into a single text file without having

> > to
> > > have all of the text files in one folder. The problem is that many of the
> > > text files have the same name, so I want them to remain in separate
> > > sub-folders. If the text files are all in the same folder, I know I can

> > just
> > > use the DOS command: copy *.txt file.txt.

>
> > > I tried using xcopy *.txt C:\file.txt /s, hoping that all the text files

> > in
> > > the subfolders of my working directory would all get copied into file
> > > C:\file.txt. But instead, it just overwrote file.txt a couple of thousand
> > > times rather than combining all the files into one big text file.

>
> > > Any advice?

>
> > I think an example would go a long way towards describing
> > your exact requirements accurately.


Check out the following utility -

http://bluefive.pair.com/txtcollector.htm


 
Reply With Quote
 
Pegasus \(MVP\)
Guest
Posts: n/a
 
      15th Mar 2007
I cannot offer any further advice unless you post ***your***
version of the batch file.


"JornyO" <(E-Mail Removed)> wrote in message
news:6AEC930B-7C3D-442B-ADA2-(E-Mail Removed)...
> I tried the code you suggested by copying and pasting it into a text file

and
> then changing the extension to .bat. I tried running it twice, once by
> double-clicking on the Batch file icon, and once from Command Prompt.

Both
> times I got the same result: a 1KB file called Collect.txt in C:\ with a
> single line of text that says: "Snapshot taken on 03/15/2007 at 9:00"

That
> batch file was in the parent folder whose subfolders contain the text

files I
> want copied into a single file.
>
> Did I miss something? Perhaps my limited knowledge of coding and

scripting
> is making blind to something that ought to be obvious.
>
>
>
> "Pegasus (MVP)" wrote:
>
> @echo off
> set HomeFolder=c:\temp
>
> Echo Snapshot taken on %date% at %time:~0,5% > c:\Collect.txt
> call :Sub %HomeFolder%
> for /F "tokens=*" %%* in ('dir /s /b /ad') do call :Sub %%*
> notepad c:\Collect.txt
> goto :eof
>
> :Sub
> pushd "%*"
> if exist *.txt (
> echo. >> c:\Collect.txt
> echo Folder=%* >> C:\Collect.txt
> echo ==================== >> c:\Collect.txt
> for %%b in (*.txt) do (
> echo %%b >> c:\Collect.txt
> type "%%b" >> c:\Collect.txt
> )
> )
> popd
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
create single .doc file from multiple .doc files? stevesaint Microsoft Word Document Management 4 8th Jun 2009 10:42 AM
Using XCOPY to copy only changed files hmm Windows XP General 15 23rd Nov 2008 07:01 AM
multiple single tiff files into a single multiple pages file.. genc ymeri Microsoft C# .NET 0 23rd May 2006 07:41 PM
combine multiple files into single file =?Utf-8?B?QnJ1Y2VT?= Microsoft Access Form Coding 2 26th Feb 2005 02:33 AM
Will xcopy copy files in use? Jeff Malka Windows XP General 1 24th Dec 2003 10:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:28 AM.