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

How to append a file from another file ?

Status
Not open for further replies.

bolobaboo

MIS
Aug 4, 2008
120
US
Hi
I am using following code ..

sSourceFile = "C:\anil\CBDSTSM01.TXT"
sDestinationFile = "C:\anil\CBDSTSM01.log"
Dim pFSO
Set pFSO = CreateObject("Scripting.FileSystemObject")
Call pFSO.appendFile(sSourceFile, sDestinationFile, True)
Call pFSO.DeleteFile(sSourceFile, True)

It did not work. Any idea ?

THX
 
What is it, .appendFile() method? That's pure imagination. Read the manual.
 
You may try something like this, supposing all textfiles are in ascii, otherwise change the parameter 0 to -1.
[tt]
'given
sSourceFile = "C:\anil\CBDSTSM01.TXT"
sDestinationFile = "C:\anil\CBDSTSM01.log"

Set pFSO = CreateObject("Scripting.FileSystemObject")

set ots=pFSo_Opentextfile(sSourceFile,1,true,[red]0[/red])
s=""
on error resume next
s=s & ots.readall
on error goto 0
ots.close
set ots=pFSo_Opentextfile(sDestinationFile,8,true,[red]0[/red])
ots.write s
ots.close
set ots=nothing

pFSO.DeleteFile sSourceFile, True
set pFSO=nothing
[/tt]
 
Hi
Tsuji
Few more help I want to run following application ...But it fails .

'given
sSourceFile = "C:\anil\CBDSTSM01.TXT"
sDestinationFile = "C:\anil\CBDSTSM01.log"
strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set wshShell = WScript.CreateObject ("WSCript.shell")
' Run application
WshShell.Run ""C:\Program Files\Tivoli\TSM\baclient\dsmadmc.exe" -TCPSERVERADDRESS=CBDSTSM1 -TCPPORT=1610 -outfile=c:\anil\CBDSTSM01.txt",1,true

' Append todays date and time to C:\anil\CBDSTSM01.log ..
Set filetxt = filesys.OpenTextFile(sDestinationFile, ForAppending, True)
filetxt.WriteLine("=================================================================")
filetxt.WriteLine("=================================================================")
filetxt.WriteLine( Todays data and time )
filetxt.WriteLine("=================================================================")
filetxt.WriteLine("=================================================================")
filetxt.Close

WScript.Sleep(80000)
Set pFSO = CreateObject("Scripting.FileSystemObject")

set ots=pFSo_Opentextfile(sSourceFile,1,true,0)
s=""
on error resume next
s=s & ots.readall
on error goto 0
ots.close
set ots=pFSo_Opentextfile(sDestinationFile,8,true,0)
ots.write s
ots.close
set ots=nothing

pFSO.DeleteFile sSourceFile, True
set pFSO=nothing
 
Scripting may not be what you earn for a living, but it still deserves a minimal of rigour to finish its little work. You have object reference(s) defined no where, constant/variable not assigned value properly, command line incorrect (even without the appending routine of my part)...
[tt]
'given
sSourceFile = "C:\anil\CBDSTSM01.TXT"
sDestinationFile = "C:\anil\CBDSTSM01.log"
strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set wshShell = WScript.CreateObject ("WSCript.shell")
' Run application
WshShell.Run "[highlight]""[/highlight]C:\Program Files\Tivoli\TSM\baclient\dsmadmc.exe[highlight]""[/highlight] -TCPSERVERADDRESS=CBDSTSM1 -TCPPORT=1610 -outfile=[blue]" & sSourceFile[/blue],1,true

' Append todays date and time to C:\anil\CBDSTSM01.log ..
[blue]Set pFSO = CreateObject("Scripting.FileSystemObject")[/blue]
[red]ForAppending=8[/red]
Set filetxt = [red]pFSO[/red].OpenTextFile(sDestinationFile, ForAppending, True)
filetxt.WriteLine("=================================================================")
filetxt.WriteLine("=================================================================")
filetxt.WriteLine( Todays data and time )
filetxt.WriteLine("=================================================================")
filetxt.WriteLine("=================================================================")
filetxt.Close

WScript.Sleep(80000)
[red]'[/red]Set pFSO = CreateObject("Scripting.FileSystemObject") 'moved up

set ots=pFSo_Opentextfile(sSourceFile,1,true,[red]-2[/red]) 'using system default format(?)
s=""
on error resume next
s=s & ots.readall
on error goto 0
ots.close
set ots=pFSo_Opentextfile(sDestinationFile,8,true,[red]-2[/red])
ots.write s
ots.close
set ots=nothing

pFSO.DeleteFile sSourceFile, True
set pFSO=nothing
[/tt]
 
Hi
Tsuji
I used ur suggestion but it did not help. How to check which part is broken ? Application still not able to start.
Thank you helping me. I have feeling arguments not getting thru to application.
If i use batch file then call that batch file in above script it works. But i want one script to do all , no seperate bacth file.

cd \progra~1\tivoli\tsm\baclient
"C:\Program Files\Tivoli\TSM\baclient\dsmadmc.exe" -TCPSERVERADDRESS=CBDSTSM1 -TCPPORT=1610 -outfile=c:\anil\CBDSTSM01.txt

 
Add this line.
[tt]
'...etc etc...
Set wshShell = WScript.CreateObject ("WSCript.shell")
[red]wshshell.currentdirectory="c:\program files\tivoli\tsm\baclient"[/red]
' Run application
WshShell.Run """C:\Program Files\Tivoli\TSM\baclient\dsmadmc.exe"" -TCPSERVERADDRESS=CBDSTSM1 -TCPPORT=1610 -outfile=" & sSourceFile,1,true
'etc etc...[/tt]
 
Further notes

The .currentdirectory mimics the cd line. That change of current directory may help if your commandline depends on some macro file(s) stored in that directory where the command line implicitly depends on or calls upon. But once it is on that current directory, the .run may further spare the path to dsmadmc.exe. That makes the line shorter.
[tt]
'...etc etc...
Set wshShell = WScript.CreateObject ("WSCript.shell")
[red]wshshell.currentdirectory="c:\program files\tivoli\tsm\baclient"[/red]
' Run application
WshShell.Run "[red]dsmadmc.exe[/red] -TCPSERVERADDRESS=CBDSTSM1 -TCPPORT=1610 -outfile=" & sSourceFile,1,true
'etc etc...
[/tt]
In any case, make sure the switch -TCPSERVERADDRESS is correct that I can't be sure.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top