Write today ProgramIt is required to write text files repeatedly, so a process function is written, hoping to be useful to everyone.
Code:
Sub write2file (strfile, strcontent, blnappend)
'Write files
'Strfile file name (PATH), content written by strcontent, and whether to append blnappend
On Error resume next
Set objfso = server. Createobject ("scripting. FileSystemObject ")
If blnappend then
Set objwritetext = objfso. opentextfile (strfile, 8, true)
Else
Set objwritetext = objfso. opentextfile (strfile, 2, true)
End if
Objwritetext. writeline (strcontent)
Set objwritetext = nothing
Set objfso = nothing
'Fault tolerance Processing
Select case err
Case 424 response. Write "The path is not found or the directory has no write permission ."
'Case else response. Write err. Description
Case else response. Write err
End select
End sub
Call method:
Write2file "C: \ dd. ini", "DD", true
Or
Call write2file ("C: \ dd. ini", "DD", true)
Note:
1. automatically create a file;
2. The directory cannot be automatically created.