Rem #################################################################
Rem ## 路径检测
Function CheckFolder(strPath)
Dim Fso
Set Fso = CreateObject("Scripting.FileSystemObject")
CheckFolder = fso.FolderExists(strPath)
End Function
Rem #################################################################
Rem #################################################################
Rem ## 路径检测
Function CheckFile(strPath)
Dim Fso
Set Fso = CreateObject("Scripting.FileSystemObject")
CheckFile = fso.FileExists(strPath)
End Function
Rem #################################################################
Rem #################################################################
Rem ## 文件名有效性检测
Private Function CheckFileName(strFileName)
CheckFileName = False
If strFileName = "" Or IsNull(strFileName) Then Exit Function
If Instr(1, strFileName, "\", 1) Then Exit Function
If Instr(1, strFileName, "/", 1) Then Exit Function
If Instr(1, strFileName, ":", 1) Then Exit Function
If Instr(1, strFileName, "*", 1) Then Exit Function
If Instr(1, strFileName, "?", 1) Then Exit Function
If Instr(1, strFileName, """", 1) Then Exit Function
If Instr(1, strFileName, "<", 1) Then Exit Function
If Instr(1, strFileName, ">", 1) Then Exit Function
If Instr(1, strFileName, "|", 1) Then Exit Function
CheckFileName = True
End Function
Rem #################################################################
Rem #################################################################
Rem ## 远程获得内容
Private Function GetContent(strUrl)
GetContent = ""
Dim oXhttp, strContent
Set oXhttp = Server.CreateObject("Microsoft.XMLHTTP")
On Error Resume Next
With oXhttp
.Open "GET", strUrl, False, "", ""
.Send
strContent = .Responsebody
strContent = BytesToBstr(strContent)
End With
Set oXhttp = Nothing
If Err.Number <> 0 Then
oSys.addmessage Err.Description
Err.Clear
Exit Function
End If
GetContent = strContent
End Function
Rem #################################################################
Rem #################################################################
Rem ## 编码转换 2进制 => 字符串
Private Function BytesToBstr(vIn)
dim objstream
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode = 3
objstream.Open
objstream.Write vIn
objstream.Position = 0
objstream.Type = 2
objstream.Charset = "GB2312"
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
Rem #################################################################
Rem #################################################################
Rem ## 编码转换 2进制 => 字符串
Private Function sDoCreateFile(strPath, strFileName, ByRef strContent)
sDoCreateFile = False
Rem ## 检测路径及文件名有效性
If Not(CheckFolder(strPath)) Then Exit Function
If Not(CheckFileName(strFileName)) Then Exit Function
If Right(strPath, 1) <> "\" Then strPath = strPath & "\"
Dim strFullFileName
strFullFileName = strPath & strFileName
Rem ## 生成文件
Dim objStream
On Error Resume Next
Set objStream = Server.CreateObject("ADODB.Stream")
If Err.Number=-2147221005 Then
oSys.addmessage "主机不支持ADODB.Stream"
Err.Clear
Exit Function
End If
On Error Resume Next
With objStream
.Type = 2
.Open
.Charset = "GB2312"
.Position = objStream.Size
.WriteText = strContent
.SaveToFile strFullFileName, 2
.Close
End With
If Err.Number <> 0 Then
oSys.addmessage strFullFileName
oSys.addmessage Err.Description
Err.Clear
Exit Function
Else
oSys.addmessage strFullFileName
End If
Set objStream = Nothing
sDoCreateFile = True
End Function
Rem #################################################################
Rem #################################################################
Rem ## 逝去时间
Private Function processTime(intFlag)
Dim IntProcessSecond, Result, dtaEnd
dtaEnd = Timer()
IntProcessSecond = FormatNumber((dtaEnd - dtaStart) * 1000, 3, True)
Select Case intFlag
Case 0
Result = "花费时间: " & IntProcessSecond & "毫秒"
Case 1
Case 2
Case 3
End Select
processTime = Result
End Function
Rem #################################################################