Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy/Append contents

Status
Not open for further replies.

jessicatech

Programmer
Oct 24, 2006
19
MY
Hello,

I need to automate the following, using scripting language (VBSCRIPT):

Copy all the contents of text files in a folder and paste all the contents to a text file (PROCESS.TXT).

Please advise and Thank you.
 
you can use dos command like this in vbs:
Code:
Set wshshell = WScript.CreateObject("WScript.Shell")  
wshshell.Run("cmd.exe /c dir /b c:\your_folder\*.* > c:\target_folder\processe.txt")
 
And what have you tried so far ?
Why not simply this command ?
COPY /Y \path\to\input\*.txt \path\to\output\process.txt

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi barny2006,

Thanks for the prompt reply. I tried the code. It copies all the text filenames (eg. test1.txt, test2.txt and test3.txt) and store it into the PROCESS.TXT file.

I would like to copy all the CONTENT of the test filenames (ie. test1.txt, test2.txt and test3.txt) and store them into the PROCESS.TXT file.

All the text files reside in the same folder.

Please advise and Thank you.
 
Hi PHV,

I tried the following in a .bat file as advised:
COPY /Y \path\to\input\*.txt \path\to\output\process.txt

It copies contents from all the text files and store into PROCESS.TXT file. However, it joins all the contents as a single string and added a funny character  at the end of the string. How can I copy the contents so that it looks exactly like the one in the original text files. Also, how can I get rid of that funny character  ?

Please advice and Thank you.
 
In a console windows type copy /? and have a look at the /A switch.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi PHV,

I added /A to indicate that it is an ASCII file, but the output is still the same, ie. the it appears a one string and the funny character is still there.

COPY /Y /A \path\to\input\*.txt \path\to\output\process.txt

Please advise.
 
How are you looking at the content of process.txt ?
If you use notepad then try wordpad instead.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi PHV,

I have the following contents in the following text files:
test1.txt
Test-1

test2.txt
Test-2

test3.txt
Test-3


The I ran the following test.bat file:
COPY /Y /A c:\suppin\*.txt c:\suppin\process.txt

I got the following content in the PROCESS.TXT file:
Test-1Test-2Test-3

I also tried opening the PROCESS.TXT file with Wordpro and the content are the same as using Notepad.

Please advise.

 
Hi tsuji,

Great! Now the funny character is not there. But it still appears as one string as follow:

Test-1Test-2Test-3

How do I make it look like the original files content as follow:
Test-1
Test-2
Test-3

Please advise and Thank you.
 
End each file at the new blank line. Otherwise, can we still call + appending? I don't know.
 
Hi tsuji,
The text files that were provided do not have the additional blank line at the end of each file.

Can I know what do you mean by "+ appending"? Which command?

Thank you.
 
Nothing essential. copy /? use "+" for finite number and named file appending to each other. Wild card appending means the same. So in a word, if you want appending more than what appending is meant for copy.exe, do something else.
 
So, your *.txt files haven't EndOfLine character ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi tsuji,

Can you please elabrote on how to use COPY and APPEND to achieve the goal? I don't get the meaning.

Another thing also, I can't use the /B for COPY command, as it indicates it is a binary file. The output text file (PROCESS.TXT) is to be an ASCII file.

Thank you.
 
>(self)if you want appending more than what appending is meant for copy.exe, do something else.
(copy is internal, so I shouldn't say copy.exe)

Suppose you have the txt file in the directory d:\test. Then you can do this.

[1] Make a single line (just a carriage return) file, call it singleline.xxx and place in your source directory (d:\test, say). Extension can be arbitrary as long as it is not txt to avoid collision.

[2] Suppose process.txt is to be at the same directory.

Then the batch file like this works good enough.
[tt]
d:
cd d:\test
del process.txt
for %%a in (*.txt) do copy /b process.xxx+%%a+singleline.xxx process.xxx
rename process.xxx process.txt
[/tt]
You get the idea.
 
Hi tsuji,

I get your point now. Thanks for the explanation. However, in my case, I wouldn't know how many files or the file names that I wanna add to the PROCESS.TXT file. All I know is that there are text files.

Please advise and Thank you.
 
The point is it does not matter how many, as long as all of them has extension .txt.
 
Hi tsuji,
I tried the following codes:
c:
cd c:\suppin
del process.txt
for %%a in (*.txt) do copy /b process.xxx+%%a+singleline.xxx process.xxx
rename process.xxx process.txt

with the following files in the folder:
process.xxx EMPTY
singleline.xxx ONE SINGLE LINE

After the above batch run, the process.xxx is changed to process.txt and has the following content:
FIRST LINE
Test-1Test-2Test-3 SECOND LINE

I need the following output:
Test-1 FIRST LINE
Test-2 SECOND LINE
Test-3 THIRD LINE

Pleas advise and Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top