我有一个VBScript程序编码,它创建一个HTML页面。使用WriteLine命令,我想知道是否可以复制文件“default.html”的代码(在同一目录中)并将其插入我的WriteLine命令。
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile(Trim(Username) & Trim(Password) & ".html",2,True)
f.WriteLine("<!-- """ & Username & """-->")
f.WriteLine(" ")
Set fs = Nothing
MsgBox "Webpage created!"
由于
答案 0 :(得分:0)
尝试以下代码:
Const FsoTristateUseDefault = -2 ' Opens the file using the system default.
Const FsoTristateTrue = -1 ' Opens the file as Unicode.
Const FsoTristateFalse = 0 ' Opens the file as ASCII.
' some operations
sUsername = "username"
sPassword = "12345"
' set path to default.html
sScriptFolder = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName) & "\"
sDefaultPath = sScriptFolder & "default.html"
' read default
sDefaultContent = ReadTextFile(sDefaultPath, FsoTristateUseDefault)
' processing some data to get result
sResult = ""
sResult = sResult & "<!-- """ & Username & """-->" & vbCrLf
sResult = sResult & " " & vbCrLf
sResult = sResult & sDefaultContent
' write result to new file, as Unicode
WriteTextFile sResult, Trim(sUsername) & Trim(sPassword) & ".html", FsoTristateTrue
Function ReadTextFile(sPath, iFormat)
With CreateObject("Scripting.FileSystemObject").OpenTextFile(sPath, 1, False, iFormat)
ReadTextFile = ""
If Not .AtEndOfStream Then ReadTextFile = .ReadAll
.Close
End With
End Function
Sub WriteTextFile(sCont, sPath, iFormat)
With CreateObject("Scripting.FileSystemObject").OpenTextFile(sPath, 2, True, iFormat)
.Write(sCont)
.Close
End With
End Sub
注意是否需要打开文件e。 G。在UTF-8中,您必须使用其他工具like ADODB.Stream