📄 filesys.class.asp
字号:
<%
'////////////////////////////////////////////////////////////////////////
'本页:
' Tsys 文件管理类
'说明:
' #方法:
' 名称 访问 简介
' -----------------------------------------------------------------
' Init 允许 文件管理类初始化
' CreateFolder 允许 在当前位置创建目录
' MoveItem 允许 移动文件、目录
' DeleteItem 允许 删除文件、目录
' SubItems 允许 获得当前目录下子目录集、文件集
' FormatPath 允许 格式化当前目录串
' GetFileEx 允许 获得文件扩展名
' FileIco 允许 获得文件扩展名对应的图标
'
'
' #属性:
' 名称 读/写 简介
' -----------------------------------------------------------------
' CurrPath 读/写 当前访问目录(不含根目录)
' CurrIndex 读/写 当前访问目录索引(既目录权限Xml文档内Index域)
' CurrRoot 读/- 当前访问目录-根目录
' CurrUrl 读/- 当前访问目录-对应Url
' CurrTitle 读/- 当前访问目录-标题
' VisuPath 读/- 完整目录(未转换)
' RealPath 读/- 完整目录(转换后)
' VisitUrl 读/- 完整目录的可访问地址
' FolderItems 读/- 目录权限列表
' CurrFolderItem 读/- 正在访问的目录权限
' IsRoot 读/- 当前是否在根目录位置
' UpLoadFext 读/- 允许上传的文件扩展名
' EditFext 读/- 允许编辑的文件扩展名
' HaveFolderItem 读/- 是否具有目录权限列表
' IsAvailable 读/- 当前访问的目录是否存在
' EnableUpload 读/- 是否允许上传
' EnableEdit 读/- 是否允许编辑
' EnableDelete 读/- 是否允许删除
' EnableMove 读/- 是否允许移动
' EnableCreate 读/- 是否允许创建
'////////////////////////////////////////////////////////////////////////
Class TFileSys
Private XMLDoc, mFolderItems, mCurrFolderItem
Private Fso, Fle
Private mCurrTitle, mCurrRoot, mCurrUrl, mCurrIndex, mCurrPath
Private mUpLoadFext, mEditFext, mEnableUpload, mEnableEdit, mEnableDelete, mEnableCreate, mEnableMove
Private mVisuPath, mRealPath, mVisitUrl
'初始化类
Private Sub Class_Initialize
Set mCurrFolderItem = Nothing
Set mFolderItems = Nothing
EnableEdit = False
EnableUpload = False
Set Fso = Server.CreateObject(Cfg.FileSystemObject_Name)
Set XMLDoc = Server.CreateObject(Cfg.XMLObject_Name)
If Admin.FolderList <> "" Then
XMLDoc.async = FALSE
XMLDoc.resolveExternals = FALSE
XMLDoc.loadXML(Admin.FolderList)
Set mFolderItems = XMLDoc.documentElement.selectNodes("//file/item")
End If
End Sub
'注消类
Private Sub Class_Terminate
Set XMLDoc = Nothing
Set Fso = Nothing
Set mCurrFolderItem = Nothing
Set mFolderItems = Nothing
End Sub
'##############################################################################################
' 方法部分
'##############################################################################################
'方法:初始化文件系统类
'返回:bool(true:初始化成功 false:初始化失败)
'取得当前所在目录项Xml节点对象'
Public Function Init()
If CurrIndex = -1 Then
Init = False
Exit Function
End If
Set mCurrFolderItem = XMLDoc.documentElement.selectSingleNode("//file/item[index = """ & CurrIndex & """]")
If mCurrFolderItem Is Nothing Then
Exit Function
End If
Dim tmpNode
Set tmpNode = mCurrFolderItem.selectSingleNode("./title")
CurrTitle = tmpNode.Text
Set tmpNode = mCurrFolderItem.selectSingleNode("./path")
CurrRoot = tmpNode.Text
Set tmpNode = mCurrFolderItem.selectSingleNode("./url")
CurrUrl = tmpNode.Text
Set tmpNode = mCurrFolderItem.selectSingleNode("./upload")
mUpLoadFext = tmpNode.Text
EnableUpload = (tmpNode.getAttribute("enable") = "1")
Set tmpNode = mCurrFolderItem.selectSingleNode("./edit")
mEditFext = tmpNode.Text
EnableEdit = (tmpNode.getAttribute("enable") = "1")
If mCurrFolderItem.selectSingleNode("./create").getAttribute("enable") = "1" Then
EnableCreate = True
Else
EnableCreate = False
End If
If mCurrFolderItem.selectSingleNode("./delete").getAttribute("enable") = "1" Then
EnableDelete = True
Else
EnableDelete = False
End If
If mCurrFolderItem.selectSingleNode("./move").getAttribute("enable") = "1" Then
EnableMove = True
Else
EnableMove = False
End If
If CurrRoot = "" Then
Init = False
Exit Function
End If
'//分析最终目录路径
If CurrPath <> "" Then
VisuPath = CurrRoot & CurrPath & "/"
VisitUrl = CurrUrl & CurrPath & "/"
Else
VisuPath = CurrRoot
VisitUrl = CurrUrl
End If
If FLib.ChkPathType(VisuPath) = 2 Then
RealPath = Server.MapPath(VisuPath) & "\"
Else
RealPath = VisuPath
End If
Init = True
End Function
'方法:在当前位置创建目录
'参数:目录名称
'
Public Function CreateFolder(PathName)
' On Error Resume Next
Fso.CreateFolder(RealPath & FormatPath(PathName))
If Err.Number = 0 Then
CreateFolder = True
Else
CreateFolder = False
End If
End Function
'方法:移动文件、目录
'参数:文件、目录名称, 目标位置
'
Public Function MoveItem(fName, Target)
' On Error Resume Next
Dim tmpPath, tmpPath2
tmpPath = RealPath & FormatPath(fName)
tmpPath2 = CurrRoot & FormatPath(Target)
If FLib.ChkPathType(tmpPath2) = 2 Then
tmpPath2 = Server.MapPath(tmpPath2)
Else
tmpPath2 = tmpPath2
End If
If Right(tmpPath2, 1) <> "/" Then
tmpPath2 = tmpPath2 & "/"
End If
Fso.MoveFile tmpPath, tmpPath2
Fso.MoveFolder tmpPath, tmpPath2
If Err.Number = 0 Then
MoveItem = True
Else
MoveItem = False
End If
End Function
'方法:检查文件、目录存在
'参数:文件、目录名称
'
Public Function FileExistsItem(fName)
' On Error Resume Next
Dim tmpPath
tmpPath = RealPath & FormatPath(fName)
If Fso.FileExists(tmpPath) Then
FileExistsItem = True
Else
FileExistsItem = False
End If
End Function
'方法:删除文件、目录
'参数:文件、目录名称
'
Public Function DeleteItem(fName)
On Error Resume Next
Dim tmpPath
tmpPath = RealPath & FormatPath(fName)
Fso.DeleteFile tmpPath
Fso.DeleteFolder tmpPath
If Err.Number = 0 Then
DeleteFile = True
Else
DeleteFile = False
End If
End Function
'方法:取得指定目录内目录集对象
'参数:
' 返回对象类型(1: 返回文件集 2:返回目录集)
'返回:
' 失败则返回Nothing(详细使用参见Microsoft Windows Script 文档)
'
Public Function SubItems(t)
' On Error Resume Next
Select Case t
Case "folder" :
Set SubItems = Fso.GetFolder(RealPath).SubFolders
Case "file" :
Set SubItems = Fso.GetFolder(RealPath).Files
Case Else :
Set SubItems = Nothing
End Select
If Err.Number <> 0 Then
Set SubItems = Nothing
End If
End Function
'函数:格式化为标准目录串
'返回:目录串
' 防止非法用使用../等符号跳过mCurrRoot目录
' 去除目录两边斜杆
Public Function FormatPath(Path)
Path = Replace(Path, "\", "/")
Path = Replace(Path, "../", "")
If Right(Path, 1) = "/" Then
Path = Left(Path, Len(Path)-1)
End If
If Left(Path, 1) = "/" Then
Path = Mid(Path, 2, Len(Path)-1)
End If
FormatPath = Path
End Function
Public Function GetFileEx(fileName)
GetFileEx = Mid(fileName, InStrRev(fileName, ".")+1)
End Function
Public Function FileIco(f_name)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -