Copy codeThe Code is as follows: '==============================================
'Get the file suffix
'==============================================
Function Get_Filetxt (ByVal t0)
Dim t1
IF Len (t0) <2 Or Instr (t0, ".") = 0 Then Get_Filetxt = False: Exit Function
T1 = Split (t0 ,".")
Get_Filetxt = Lcase (t1 (Ubound (t1 )))
End Function
'==============================================
'The pure code for reading any file
'==============================================
Function LoadFile (ByVal t0)
IF Len (t0) = 0 Then Exit Function
IF Sdcms_Cache Then
IF Check_Cache ("LoadFile _" & t0) Then
Create_Cache "LoadFile _" & t0, LoadFile_Cache (t0)
End IF
LoadFile = Load_Cache ("LoadFile _" & t0)
Else
LoadFile = LoadFile_Cache (t0)
End IF
End Function
Function LoadFile_Cache (ByVal t0)
Dim t1, stm
On Error Resume Next
IF Len (t0) = 0 Then Exit Function
T1 = Empty
Set Stm = Server. CreateObject ("Adodb. Stream ")
With Stm
. Type = 2' read in this mode
. Mode = 3
. Charset = CharSet
. Open
. Loadfromfile Server. MapPath (t0)
T1 =. readtext
. Close
End
Set Stm = Nothing
IF Err Then
LoadFile_Cache = "" & t0 & "" & Err. Description: Err. Clear
Else
LoadFile_Cache = t1
End IF
End Function
'==============================================
'Check whether the file exists
'==============================================
Function Check_File (ByVal t0)
Dim Fso
T0 = Server. MapPath (t0)
Set Fso = CreateObject ("Scripting. FileSystemObject ")
Check_File = Fso. FileExists (t0)
Set Fso = Nothing
End Function
'==============================================
'Check whether the folder exists
'==============================================
Function Check_Folder (ByVal t0)
Dim Fso
T0 = Server. MapPath (t0)
Set Fso = CreateObject ("Scripting. FileSystemObject ")
Check_Folder = Fso. FolderExists (t0)
Set Fso = Nothing
End Function
'==============================================
'Create a folder (unlimited)
'==============================================
Function Create_UpFile (ByVal t0)
Dim t1, t2, objFSO, I
On Error Resume Next
T0 = Server. MapPath (t0)
IF InStr (t0, "\") <= 0 Or InStr (t0, ":") <= 0 Then: Create_upfile = False: Exit Function
Set objFSO = CreateObject ("Scripting. FileSystemObject ")
IF objFSO. FolderExists (t0) Then: Create_upfile = True: Exit Function
T1 = Split (t0, "\"): t2 = ""
For I = 0 To UBound (t1)
T2 = t2 & t1 (I )&"\"
IF Not objFSO. FolderExists (t2) Then objFSO. CreateFolder (t2)
Next
Set objFSO = Nothing
IF Err = 0 Then Create_upfile = True: Else Create_upfile = False: Echo "Create_upfile:" & Err. Description & "<br>": Err. Clear
End Function
Sub SaveFile (ByVal t0, ByVal t1, ByVal t2)
Dim objFSO, t3
Set objFSO = CreateObject ("Scripting. FileSystemObject ")
IF t0 = "" Then Echo "directory cannot be blank! ": Died
T3 = Server. MapPath (t0)
IF t2 = "" Or IsNull (t2) Then t2 = ""
IF objFSO. FolderExists (t3) = False Then Create_upfile (t0)
BuildFile t3 & "\" & Trim (t1), t2
Set objFSO = Nothing
End Sub
Function BuildFile (ByVal t0, ByVal t1)
Dim Stm
On Error Resume Next
Set Stm = Server. CreateObject ("Adodb. Stream ")
With Stm
. Type = 2' read in this mode
. Mode = 3
. Charset = CharSet
. Open
. WriteText t1
. SaveToFile t0, 2
. Close
End
Set Stm = Nothing
IF Err Then Echo "BuildFile:" & Err. Description & "<br>": Err. Clear
End Function
'==============================================
'Rename the folder
'==============================================
Sub RenameFile (ByVal t0, ByVal t1)
Dim Fso
On Error Resume Next
Set Fso = Server. CreateObject ("Scripting. FileSystemObject ")
IF Fso. FolderExists (Server. MapPath (t0) Then
Fso. MoveFolder Server. MapPath (t0), Server. MapPath (t1)
End IF
Set Fso = Nothing
IF Err Then Echo "Renamefile:" & Err. Description & "<br>": Err. Clear
End Sub
'==============================================
'Rename the file
'==============================================
Sub RenameHtml (ByVal t0, ByVal t1)
Dim Fso
On Error Resume Next
Set Fso = Server. CreateObject ("Scripting. FileSystemObject ")
IF Fso. FileExists (Server. MapPath (t0) Then
Fso. MoveFile Server. MapPath (t0), Server. MapPath (t1)
End IF
Set Fso = Nothing
IF Err Then Echo "Renamehtml:" & Err. Description & "<br>": Err. Clear
End Sub
'==============================================
'Delete a folder
'==============================================
Sub DelFile (ByVal t0)
Dim Fso, F
On Error Resume Next
Set Fso = Server. CreateObject ("Scripting. FileSystemObject ")
Set F = fso. GetFolder (Server. MapPath (t0 ))
IF Not IsNull (t0) Then F. Delete True
IF Err Then Echo "Delfile:" & Err. Description & "<br>": Err. Clear
End Sub
'==============================================
'Delete an object
'==============================================
Sub DelHtml (ByVal t0)
Dim Fso
On Error Resume Next
Set Fso = Server. CreateObject ("Scripting. FileSystemObject ")
IF Fso. FileExists (Server. MapPath (t0) Then Fso. DeleteFile Server. MapPath (t0)
IF Err Then Echo "DelHtml:" & Err. Description & "<br>": Err. Clear
End Sub
Function Re_FileName (ByVal t0)
Dim t1
T0 = Lcase (t0)
IF Len (t0) = 0 Then Re_FileName = "{id}": Exit Function
T1 = Now ()
'Process custom file names
'If Instr (t0, "{")> 0 And Instr (t0, "}")> 0 Then
'If Instr (t0, "{id}") = 0 Then
'T0 = t0 & "{id}" 'try to prevent duplication
'End IF
'End IF
T0 = Replace (t0, "{y}", Year (t1 ))
T0 = Replace (t0, "{m}", Right ("0" & Month (t1), 2 ))
T0 = Replace (t0, "{d}", Right ("0" & Day (t1), 2 ))
T0 = Replace (t0, "{h}", Right ("0" & Hour (t1), 2 ))
T0 = Replace (t0, "{mm}", Right ("0" & Minute (t1), 2 ))
T0 = Replace (t0, "{s}", Right ("0" & Second (t1), 2 ))
Re_FileName = t0
End Function