asp中文件与文件夹常用处理函数(文件后缀、创建(2)


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 '以本模式读取
.Mode=3
.Charset=CharSet
.Open
.WriteText t1
.SaveToFile t0,2
.Close
End With
Set Stm=Nothing
IF Err Then Echo "BuildFile:"&Err.Description&"<br>":Err.Clear
End Function

'=====================================
'重命名文件夹
'=====================================
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

'=====================================
'重命名文件
'=====================================
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

'=====================================
'删除文件夹
'=====================================
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

'=====================================
'删除文件
'=====================================
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()
'处理自定义文件名

'IF Instr(t0,"{")>0 And Instr(t0,"}")>0 Then
'IF Instr(t0,"{id}")=0 Then
't0=t0&"{id}"'尽量防止重复
'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