'//提供文件處理通用接口
Class FileSystemObject
'/*
' * 功能描述:刪除文件
' * 輸入?yún)?shù):FileName——文件相對(duì)路徑
'*/
Public Function DelFile(FileName)
Dim getPath
getPath="/"
SET Fso=Server.CreateObject("Scripting.FileSystemObject")
getPath=Replace(getPath&FileName,"//","/")
if Fso.FileExists(Server.MapPath(getPath))=True then
Fso.DeleteFile Server.mappath(getPath)
End if
Set Fso=Nothing
End Function
'/*
' * 功能描述:判斷路徑是否存在,如不存在則創(chuàng)建
' * 輸入?yún)?shù):SaveFilePath——相對(duì)路徑,如:/UploadFiles/NewsFiles
'*/
Public Function CreatePath(SaveFilePath)
Dim DeclarePath,FileObj,FilePath
DeclarePath="/"
Set FileObj=Server.CreateObject("Scripting.FileSystemObject")
For Each FilePath in split(SaveFilePath,"/")
DeclarePath=Replace(DeclarePath&FilePath&"/","//","/")
if FileObj.FolderExists(Server.MapPath(DeclarePath))=false then
FileObj.CreateFolder(Server.MapPath(DeclarePath))'創(chuàng)建文件夾
end if
Next
Set FileObj=nothing
CreatePath=DeclarePath
End Function
'/*
' * 功能描述:重命名文件夾
' * 輸入?yún)?shù):GetPath——文件夾路徑
' * 輸入?yún)?shù):OldName——舊的文件夾名稱
' * 輸入?yún)?shù):NewName——新的文件夾名稱
'*/
Public Function RenFolder(GetPath,OldName,NewName)
Dim Fso
if OldName="" or NewName="" then
exit Function
else
if OldName=NewName then exit Function
end if
SET Fso=Server.CreateObject("Scripting.FileSystemObject")
if Fso.FolderExists(Server.MapPath(GetPath&NewName)) then
response.write"<script language=javascript>alert('目錄已經(jīng)存在!!');this.history.go(-1);</script>"
response.end()
end if
'//舊的文件夾不存在,則創(chuàng)建
if Not Fso.FolderExists(Server.MapPath(GetPath&OldName)) Then
CreatePath(GetPath&OldName)
End if
Fso.MoveFolder Server.MapPath(GetPath&OldName),Server.MapPath(GetPath&NewName)
set Fso=nothing
'response.redirect request.ServerVariables("HTTP_REFERER")
End Function
'/*
' * 功能描述:保存當(dāng)前文件
' * 輸入?yún)?shù):GetPath——文件路徑
' * 輸入?yún)?shù):GetContent——保存的內(nèi)容
' * 輸入?yún)?shù):GetFile——保存的文件名
'*/
Public Function SaveEditFile(GetPath,GetContent,GetFile)
if GetContent="" or GetFile="" then exit Function
SET Fso=Server.CreateObject("Scripting.FileSystemObject")
set CF=Fso.CreateTextFile(Server.mappath(GetPath&GetFile),true)
CF.write GetContent
CF.Close
set CF=nothing
set Fso=nothing
'response.redirect request.ServerVariables("HTTP_REFERER")
End Function
End Class