PDA

View Full Version : xp command, trying to copy contents of 900 text files into 1 help


rive22
07-08-2006, 12:34 PM
I'm trying to copy all of the contents of nearly 1200 text files into just 1 text file. Can someone tell me how I can do this using the command prompt, what codes and how I can do it? Please.

Thank you :)

u8myrice
07-08-2006, 12:48 PM
Hmm, this is interesting. I wanna know also. Might be useful one day.

nessus
07-08-2006, 01:21 PM
I'm trying to copy all of the contents of nearly 1200 text files into just 1 text file. Can someone tell me how I can do this using the command prompt, what codes and how I can do it? Please.

Thank you :)

Don't know of a batch file.

Paste the following text into a file and rename it to .vbs after updating the pathing and it should work. Put all of your text files in one directory(c:\yourdirectory\ in the code below, the trailing backslash is required), with the .vbs file in another directory.
Double click the .vbs file. The contents of the text files will be put together and saved as "compiled.txt" in the same directory as the .vbs file. The files will be concatenated in the same order as Windows lists them in a list view.

'start of code
set ofso=createobject("scripting.filesystemobject")
set ofolder=ofso.getfolder("c:\yourdirectory\")
set oouput=ofs.opentextfile("compiled.txt")
for each file in ofolder.files
do until file.atendofstream
input=file.readline
ooutput.writeline input
loop
next
'end of code

EDIT: My code was indented with spaces to make the logic clearer, but it doesn't show that way when saved.

Frobozz
07-08-2006, 01:39 PM
C:\temp>type *.txt > outputfile.tmp

that should do what you asked.


edit: with the example above your output file will need to have a different extension from .txt or else it will duplicate your data when it gets to that file. :p Alternatively you could put the output file into a different directory and then have it be a .txt ... but then it's just an extension so who really cares.

rive22
07-08-2006, 02:20 PM
Thanks guys I appreciate the help big time. I'm a bit new when it comes to doing this sort of thing so I'm not completly getting it right just yet. I tried the first way doing the vbs file did everything the way mentioned but i get this error when i double click the vbs file.

http://i29.photobucket.com/albums/c262/Blazingsevens/error.jpg

the second way also looks easy but im not sure what to put in place of that type*txt part.

all my text files are in one folder and they are number 1-1200 in order. i put 10 files in a folder and named the folder "test" to try this out. is there any way i could get you guys to show me an exact example of how to do it with that? then i could use that example from there with the whole folder. im just a little new at this. but can learn very fast. i appreciate this a bunch, thanks guys :)

rive22
07-08-2006, 02:22 PM
also the folder and files are in the right location and this is what i put in the vob file;


set ofso=createobject("scripting.filesystemobject")
set ofolder=ofso.getfolder("C:\test\")
set oouput=ofs.opentextfile("compiled.txt")
for each file in ofolder.files
do until file.atendofstream
input=file.readline
ooutput.writeline input
loop
next

Frobozz
07-08-2006, 02:59 PM
the second way also looks easy but im not sure what to put in place of that type*txt part.
C:\temp>type *.txt > outputfile.tmp

type - displays the contents of a file. generally the output is sent to your display.

*.txt - * is a wildcard meaning everything. So *.txt means everything that has a .txt extension. this would include 1.txt, 2.txt, dog.txt and so on.

> - this directs where you want the output to go. By putting outputfile.tmp after it you are telling it to put the received ouput into that file. You could do a few different things with it like > com1 to send it to a serial port, or > lpt1 for a printer.

So with C:\temp>type *.txt > outputfile.tmp you are telling it to 'type all .txt files in the current directory and redirect the output into the output.tmp file also in the current directory'.

nessus
07-08-2006, 03:52 PM
set oouput=ofso.opentextfile("compiled.txt",8,true)

Update the above line. This creates the "compiled.txt" file if it does not already exist.

The way I had it before, the compiled.txt file had to exist before you ran the script. This way, it will create it if needed. If it already exists, it will append to it.

rive22
07-08-2006, 04:19 PM
cool i got it, thanks a lot guys!!