Copy Code code as follows:
<%
' Create a folder function
Function CreateFolder (strfolder) ' parameter is a relative path
' Preferred to determine if the folder you want to establish already exists
Dim Strtestfolder,objfso
Strtestfolder = Server.MapPath (strfolder)
Set objFSO = CreateObject ("Scripting.FileSystemObject")
' Check if 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 folder
Function Delfolder (strfolder) ' parameter is a relative path
Strtestfolder = Server.MapPath (strfolder)
Set objFSO = CreateObject ("Scripting.FileSystemObject")
' Check if the folder exists
If objfso.folderexists (Strtestfolder) Then
Objfso.deletefolder (Strtestfolder)
End If
Set objFSO = Nothing
End Function
' Create a text file
Function CreateTextFile (fileurl,filecontent) ' parameter is relative path and content to write to file
Set objFSO = Server.CreateObject ("Scripting.FileSystemObject")
Set fout = objFSO.CreateTextFile (Server.MapPath (FileURL))
Fout. WriteLine filecontent
Fout.close
Set objFSO = Nothing
End Function
' Delete file (for all files)
Function deltextfile (fileurl) ' parameter is a relative path
Set objFSO = CreateObject ("Scripting.FileSystemObject")
FileURL = Server.MapPath (FileURL)
If Objfso.fileexists (fileurl) Then ' check if file exists
objFSO.DeleteFile (Server.MapPath (FileURL))
End If
Set objFSO = Nothing
End Function
' Create a picture file and save the picture data stream
Function createimage (fileurl,imagecontent) ' parameter is relative path and file content
Set objstream = Server.CreateObject ("ADODB. Stream ")" To create a ADODB.stream object that must be ADO more than 2.5 version
objStream.Type = 1 ' Open in binary mode
objStream.Open
Objstream.write imagecontent ' writes string contents to buffer
Objstream. SaveToFile Server.MapPath (FileURL), 2 '-writes buffered content to file
Objstream. Close () ' Closes object
Set objstream=nothing
End Function
' Remote access to 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 = "Server gets file contents error"
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
' Get Picture data stream
Function getpic (URL)
On Error Resume Next
Dim http
Set Http=server.createobject ("Msxml2.xmlhttp") ' uses XMLHTTP method to get the contents of a picture
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 = "Server gets file contents error"
Err. Clear
End If
End Function
' Open file (text form)
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 file suffix name
function Getfileextname (fileName)
Dim pos
Pos=instrrev (FileName, ".")
If Pos>0 Then
Getfileextname=mid (filename,pos+1)
Else
Getfileextname= ""
End If
End Function
%>