Copy codeThe Code is as follows: <%
'Create a folder Function
Function CreateFolder (strFolder) 'parameter is relative path
'The first choice is to determine whether the folder to be created already exists
Dim strTestFolder, objFSO
StrTestFolder = Server. Mappath (strFolder)
Set objFSO = CreateObject ("Scripting. FileSystemObject ")
'Check whether the folder exists
If not objFSO. FolderExists (strTestFolder) Then
'Create a folder if it does not exist.
ObjFSO. CreateFolder (strTestFolder)
End If
Set objFSO = Nothing
End function
'Delete a folder
Function DelFolder (strFolder) 'parameter is relative path
StrTestFolder = Server. Mappath (strFolder)
Set objFSO = CreateObject ("Scripting. FileSystemObject ")
'Check whether the folder exists
If objFSO. FolderExists (strTestFolder) Then
ObjFSO. DeleteFolder (strTestFolder)
End if
Set objFSO = Nothing
End function
'Create a text file
The Function Createtextfile (fileurl, filecontent) 'parameter is the relative path and the content of the file to be written.
Set objFSO = Server. CreateObject ("Scripting. FileSystemObject ")
Set fout = objFSO. CreateTextFile (Server. MapPath (fileurl ))
Fout. WriteLine filecontent
Fout. close
Set objFSO = Nothing
End Function
'Delete an object (applicable to all objects)
Function Deltextfile (fileurl) 'parameter is relative path
Set objFSO = CreateObject ("Scripting. FileSystemObject ")
Fileurl = Server. MapPath (fileurl)
If objFSO. FileExists (fileurl) then' check whether the file exists
ObjFSO. DeleteFile (Server. mappath (fileurl ))
End if
Set objFSO = nothing
End Function
'Create an image file and save the image data stream
Function Createimage (fileurl, imagecontent) 'parameter is relative path and file content
Set objStream = Server. CreateObject ("ADODB. Stream") 'creates an ADODB. Stream object, which must be of version ADO 2.5 or later.
ObjStream. Type = 1' open in binary mode
ObjStream. Open
Objstream. write imagecontent writes string content to the buffer
Objstream. SaveToFile server. mappath (fileurl), 2'-Write the buffered content to the file
Objstream. Close () 'Close the object
Set objstream = nothing
End Function
'Remotely retrieve file data
Function getHTTPPage (url)
'On Error Resume Next
Dim http
Set http = Server. createobject ("Microsoft. XMLHTTP ")
Http. open "GET", url, false
Http. send ()
If Http. readystate <> 4 then
Exit function
End if
GetHTTPPage = bytesToBSTR (Http. responseBody, "GB2312 ")
Set http = nothing
If Err. number <> 0 then
GetHTTPPage = "An error occurred while obtaining the file content on the server"
Err. Clear
End If
End function
Function BytesToBstr (body, Cset)
Dim objstream
Set objstream = Server. CreateObject ("adodb. stream ")
Objstream. Type = 1
Objstream. Mode = 3
Objstream. Open
Objstream. Write body
Objstream. Position = 0
Objstream. Type = 2
Objstream. Charset = Cset
BytesToBstr = objstream. ReadText
Objstream. Close
Set objstream = nothing
End Function
'Retrieve image data streams
Function getpic (url)
On error resume next
Dim http
Set http = server. createobject ("MSXML2.XMLHTTP") 'uses the xmlhttp method to obtain the image content
Http. open "GET", url, false
Http. send ()
If Http. readystate <> 4 then
Exit function
End if
Getpic = Http. responseBody
Set http = nothing
If err. number <> 0 then
Getpic = "An error occurred while obtaining the file content on the server"
Err. Clear
End if
End Function
'Open the file (in text format)
Function OpenFile (fileurl) 'file relative path
Dim Filename, fso, hndFile
Filename = fileurl
Filename = Server. MapPath (Filename)
Set objfso = CreateObject ("Scripting. FileSystemObject ")
If objfso. FileExists (Filename) Then
Set hndFile = objfso. OpenTextFile (Filename)
OpenFile = hndFile. ReadAll
Else
OpenFile = "file read error"
End If
Set hndFile = Nothing
Set objfso = Nothing
End Function
'Get the file suffix
Function getFileExtName (fileName)
Dim pos
Pos = Limit Rev (filename ,".")
If pos> 0 then
GetFileExtName = mid (fileName, pos + 1)
Else
GetFileExtName = ""
End if
End function
%>