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

Overwrite textfile

Status
Not open for further replies.

slint

Technical User
Jul 2, 2006
48
SE
How can i overwrite a txt file if it exist and create the txt file if it dosent exist, i have tried the code below but with no luck.

Code:
Set fso = CreateObject("Scripting.FileSystemObject")


Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists("C:\Data\SCRIPTS\") Then
    If objFSO.FileExists("C:\Data\SCRIPTS\" & strComputer & ".txt") Then
        
        
        Set ts = Fso.OpenTextFile ("C:\Data\SCRIPTS\" & strComputer & ".txt", ForWriting, TRUE)
    	ts.write report
		ts.write software
    
    Else
        Set ts = fso.CreateTextFile ("C:\Data\SCRIPTS\" & strComputer & ".txt", ForWriting)
		ts.write report
		ts.write software
    
    End If
    
End If
 
[tt]Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.CreateTextFile ("C:\Data\SCRIPTS\" & strComputer & ".txt", true)
ts.write report
ts.write software
ts.close
[/tt]
 
simple... but still, out of my lead..

Thanks tsuji!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top