Copying files from command prompt

G

Guest

I am having trouble figuring out how to copy multiple files from multiple
directories into a single file.

I have a file structure like this:

C:
\20060101
\20060102
\20060103
...

Each directory has several files named like this: 1.txt, 2.txt, 3.txt, ...

What I want to do is copy each 3.txt file from each subdirectory into a
single file. Basically, I want something that works like this (this command
doesn't work):

copy c:\*\3.txt c:\appendedfile.txt

I've tried variations of both copy and xcopy with no luck. Hoping someone
here has an idea. I'd even take a solution that you can do from the Window
XP UI (using Search or something like that).
 
A

Ayush

Replied to [MatthewR]s message :
I am having trouble figuring out how to copy multiple files from multiple
directories into a single file.

I have a file structure like this:

C:
\20060101
\20060102
\20060103
...

Each directory has several files named like this: 1.txt, 2.txt, 3.txt, ...

What I want to do is copy each 3.txt file from each subdirectory into a
single file. Basically, I want something that works like this (this command
doesn't work):

copy c:\*\3.txt c:\appendedfile.txt

I've tried variations of both copy and xcopy with no luck. Hoping someone
here has an idea. I'd even take a solution that you can do from the Window
XP UI (using Search or something like that).


I think VBs or JS will be a better solution for this (post in vbs, js or wsh group).


Good Luck, Ayush.
 
C

cornedbeef007-groups

I am having trouble figuring out how to copy multiple files from multiple
directories into a single file.

I have a file structure like this:

C:
\20060101
\20060102
\20060103
...

Each directory has several files named like this: 1.txt, 2.txt, 3.txt, ...

What I want to do is copy each 3.txt file from each subdirectory into a
single file. Basically, I want something that works like this (this command
doesn't work):

copy c:\*\3.txt c:\appendedfile.txt

I've tried variations of both copy and xcopy with no luck. Hoping someone
here has an idea. I'd even take a solution that you can do from the Window
XP UI (using Search or something like that).

use copy /? to see the options for copy command.

You can specify multiple source files in a copy like this

copy source1.txt + source2.txt + source3.txt destination.txt

you can include the path in the source file

copy c:\dir1\1.txt + c:\dir2\1.txt + c:\dir3\1.txt c:
\appendedfile.txt

You can use absolute path as above, or relative path.

Go for it!

Good Luck,
Barry.
 
3

3c273

I just tried your example and it works fine here. If it is not working for
you, you could download the GNU Utilities (Open Source/Freeware) which
contains a win32 port of the unix "cat" command which does what you want.
Louis
 
G

Guest

The problem is that there are hundreds of subdirectories which I'd have to
concatenate one at a time. :(
 
A

Ayush

Replied to [MatthewR]s message :
The problem is that there are hundreds of subdirectories which I'd have to
concatenate one at a time. :(


OK, if you dont want to use VBS then :
Open the folder with multiple subfolders in explorer
Click Search at top
Enter 3.txt in Find box and after search is done, copy all the files in one directory.
Make a bat file :

type C:\TheDirectoryWith3.TxFiles\*.* > SomeFile


Run it


And you can list the 3.txt files without searching by using this command:
Go into the directory and run :

dir /s /a-d /b "3.txt"

or from anywhere :
dir /s /a-d /b "Folder\3.txt"

but i dont know how to send it to copy or type command.It is possible by sending the
dir result to text file then reading the text file line/by/line and run the command
but i dont know how..


Good Luck, Ayush.
 
G

Guest

Thanks for the tip on the GNU utilities. I don't think I'll end up using
them here but I'll likely find use for them in the future. (Why can't
Microsoft put this kind of useful functionality in their command line tools?)

I've decided to simply rename the files in each directory so that they use
the directory name in the extention. "3.txt" in the "\20060101" directory
becomes "3.txt_20060101". That way I can just use the Windows Search
funcationality to find all "3.*" files and copy them to a new folder and use
the copy command to concatenate them all.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top