代码:
复制代码 代码如下:
Sub Write2File(strFile, strContent, blnAppend)
' 写入文件
' strFile 文件名(路径) , strContent 写入的内容, 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
' 容错处理
Select Case Err
Case 424 Response.Write "路径未找到或者该目录没有写入权限."
' Case Else Response.Write Err.Description
Case Else Response.Write Err
End Select
End Sub
Write2File "c:\dd.ini", "dd", True
或者
Call Write2File ("c:\dd.ini", "dd", True)
说明:
1.自动建立文件;
2.不能自动建立目录