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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please help with VB script on combine file

Status
Not open for further replies.

aiquyen

Technical User
Mar 25, 2003
8
0
0
US
Hi,

I really need a VB script that take the contents of file A and combine it with the contents of file B, presenting it in the form of a file C.

Thanks

Van
 
This is VB ... not VB Script so some minor changes will be required
Code:
Dim FSO       As New FileSystemObject
Dim Tst_out   As TextStream
Set Tst_out = FSO.CreateTextFile("C:\FileC")
Tst_out.Write FSO.OpenTextFile("C:\FileA").ReadAll
Tst_out.Write FSO.OpenTextFile("C:\FileB").ReadAll
Tst_out.Close
 
The old DOS "copy c:\filea + c:\fileb c:\filec" will concatenate filea and fileb and put the result in filec. I tried putting it in a shell command and kept getting a File not Found error. Perhaps someone else knows how to do that?
 
Bob,

I can't explain it, but I know how to make it work.

Shell "[red]cmd /c [/red]copy C:\FileA.txt + C:\FileB.txt C:\FileC.txt"

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
I tried that, I thought. Does the /c switch have to do with it?
 
hmmm... that shell command should work... stupid question, though... If you're using long filenames, are you encapsulating your filenames with quotes? Just a thought!
 
I don't think so, because I was using c:\temp\filea.txt and so on. Actually, I have no idea why that didn't work last time. I did George's command and it worked fine.

When I didn't do the /c switch, the command window came up and none of the copy command executed. Makes sense, thanks George.

Bob
 
Bob,

For me, this is one of those, "Oh well, I don't understand it, but I know how to use it" situations.

I remembered seeing this in the VB forum a while ago (but in a different context).

I even tried looking this up, but it didn't really make sense to me. Maybe it will to you. Here's what I did...

click Start -> Run
Type: %Windir%\Help\ntcmds.chm
Click OK

To a search on cmd
double click on the topic titled "cmd"

In there, you'll see all the parameters listed.

And here's what you get....

Help File said:
CmdStarts a new instance of the command interpreter, Cmd.exe. Used without parameters, cmd displays Windows XP version and copyright information.

Syntax
cmd [[{/c|/k}] [/s] [/q] [/d] [{/a|/u}] [/t:fg] [/e:{on|off}] [/f:{on|off}] [/v:{on|off}] string]

Parameters
/c
Carries out the command specified by string and then stops.
/k
Carries out the command specified by string and continues.
/s
Modifies the treatment of string after /c or /k.
/q
Turns the echo off.
/d
Disables execution of AutoRun commands.
/a
Creates American National Standards Institute (ANSI) output.
/u
Creates Unicode output.
/t:fg
Sets the foreground f and background g colors. The following tables lists valid hexadecimal digits that you can use as the values for f and g. Value Color
0 Black
1 Blue
2 Green
3 Aqua
4 Red
5 Purple
6 Yellow
7 White
8 Gray
9 Light blue
A Light green
B Light aqua
C Light red
D Light purple
E Light yellow
F Bright white

/e:eek:n
Enables command extensions.
/e:eek:ff
Disables commands extensions.
/f:eek:n
Enables file and directory name completion.
/f:eek:ff
Disables file and directory name completion.
/v:eek:n
Enables delayed environment variable expansion.
/v:eek:ff
Disables delayed environment variable expansion.
string
Specifies the command you want to carry out.
/?
Displays help at the command prompt.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Well, now, isn't that fun! cmd /t:17 and you're back in the good old days of edit.com, with regard to colors. So, if you don't put any switches, cmd ignores the string afterwards. "cmd dir" fails to provide a directory listing, for example. On the other hand, "cmd /k dir" opens the window and shows the directory listing as well. "cmd /c dir >temp.txt" would put the directory listing into the file temp.txt and not show the command window.

On the other hand, I can't say with any confidence what "delayed environment variable expansion" is. Perhaps someday I'll look it up...

Thanks George,

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top