<%
Class DmFso	

Private Fso
Public 	FsoObj

Private Sub Class_Initialize
	Set Fso=Server.CreateObject("Scripting.FileSystemObject")
	Set FsoObj=Fso
End Sub

Private Sub Class_Terminate
	Set Fso=Nothing
	Set FsoObj=Nothing
End Sub

Function IsObjInstalled(ClassStr)
	On Error Resume Next
	IsObjInstalled=False
	Err=0
	Dim TestObj
	Set TestObj=Server.CreateObject(ClassStr)
	If 0=Err Then IsObjInstalled=True
	Set TestObj=Nothing
	Err=0
End Function

Function GetPath(Byval FileDir)
	GetPath=Server.MapPath(FileDir)
End Function

Function CheckFile(Byval FileDir)
	If Fso.FileExists(GetPath(FileDir)) Then
		CheckFile=True
	Else
		CheckFile=False
	End If
End Function

Function GetFileInfo(Byval FileDir,Byval InfoType)
	If CheckFile(FileDir) Then
		Dim F
		Set F=Fso.GetFile(GetPath(FileDir))
		Select Case InfoType
			Case 1 GetFileInfo=F.Datecreated
			Case 2 GetFileInfo=F.DateLastAccessed
			Case 3 GetFileInfo=F.DateLastModified
			Case 4 GetFileInfo=F.Path
			Case 5 GetFileInfo=F.Name
			Case 6 GetFileInfo=F.Type
			Case 7 GetFileInfo=F.Size
			Case 8 GetFileInfo=F.ParentFolder
			Case 9 GetFileInfo=F.RootFolder
			Case 0 
			GetFileInfo=F.Datecreated&"@"&F.DateLastAccessed&"@"&F.DateLastModified
			GetFileInfo=GetFileInfo&"@"&F.Path&"@"&F.Name&"@"&F.Type&"@"&F.Size
			GetFileInfo=GetFileInfo&"@"&F.ParentFolder
		End Select
		Set F=Nothing
	Else
		GetFileInfo=False
	End If
End Function

Function GetFileExt(FileDir)
	If FileDir<>"" Then
		GetFileExt=Lcase(Mid(FileDir,InstrRev(FileDir,".")+1))
	Else
		GetFileExt=False
	End If
End Function

Function ReadFile(Byval FileDir)
	If CheckFile(FileDir)=False Then
		ReadFile=False
		Exit Function
	Else
		Dim F
		Set F=Fso.OpenTextFile(GetPath(FileDir))
		ReadFile=F.ReadAll
		Set F=Nothing
	End If
End Function

Function CreateFile(Byval FileDir,Byval FileContent,Byval IsMake)
	If CheckFile(FileDir) Then
		If IsMake=True Then
			Dim F
			Set F=Fso.CreateTextFile(GetPath(FileDir),True)
			F.Write FileContent
			CreateFile=True
			Set F=Nothing
		Else
			CreateFile=False
		End If
	Else
		Set F=Fso.CreateTextFile(GetPath(FileDir),True)
		F.Write FileContent
		CreateFile=True
		Set F=Nothing
	End If
End Function

Function WriteFile(Byval FileDir,Byval FileContent,ByVal WriteType)
	If CheckFile(FileDir) Then
		Dim F
		Set F=Fso.OpenTextFile(GetPath(FileDir),WriteType)
		F.Write FileContent
		Set F=Nothing
		WriteFile=True
	Else
		WriteFile=False
	ENd If
End Function

Function MoveFile(Byval FileDir,Byval NewFileDir)
	If CheckFile(FileDir) And  CheckFile(NewFileDir)=False Then
		Fso.MoveFile GetPath(FileDir),GetPath(NewFileDir)
		MoveFile=True
	Else
		MoveFile=False
	End If
End Function

Function CopyFile(Byval FileDir,Byval NewFileDir)
	If CheckFile(FileDir) Then
		Dim F
		Set F=Fso.GetFile(GetPath(FileDir))
		F.Copy (GetPath(NewFileDir))
		CopyFile=True
		Set F=Nothing
	Else
		CopyFile=False
	End If
End Function

Function DelFile(Byval FileDir)
	If CheckFile(FileDir) Then
		Fso.DeleteFile(GetPath(FileDir))
		DelFile=True
	Else
		DelFile=False
	End If
End Function

Function CheckFolder(Byval FolderDir)
	If Fso.FolderExists(GetPath(FolderDir)) Then
		CheckFolder=True
	Else
		CheckFolder=False
	End If
End Function

Function GetFolderInfo(Byval FolderDir,Byval InfoType)
	If CheckFolder(FolderDir) Then
		Dim F
		Set F=Fso.GetFolder(GetPath(FolderDir))
		Select Case InfoType
			Case 1 GetFolderInfo=F.Datecreated
			Case 2 GetFolderInfo=F.DateLastAccessed
			Case 3 GetFolderInfo=F.DateLastModified
			Case 4 GetFolderInfo=F.Path
			Case 5 GetFolderInfo=F.Name
			Case 6 GetFolderInfo=F.Type
			Case 7 GetFolderInfo=F.Size
			Case 8 GetFolderInfo=F.ParentFolder
			Case 9 GetFolderInfo=F.RootFolder
			Case 0 
			GetFolderInfo=F.Datecreated&"@"&F.DateLastAccessed&"@"&F.DateLastModified
			GetFolderInfo=GetFolderInfo&"@"&F.Path&"@"&F.Name&"@"&F.Type&"@"&F.Size
			GetFolderInfo=GetFolderInfo&"@"&F.ParentFolder
		End Select
		Set F=Nothing
	Else
		GetFolderInfo=False
	End If
End Function

Function CreateFolder(Byval FolderStr)
	Dim I,Folder,Dir
	If InStr(FolderStr,"/")>0 Or InStr(FolderStr,"\")>0 Then
		FolderStr=Replace(FolderStr,"/","\")
		Folder=Split(FolderStr,"\")
		If Left(FolderStr,2)=".." Then
			Dir="..\"
		Else
			Dir=Dir
		End If
		If Folder(0)="" Then Dir=Dir&"\"
		For I=0 To Ubound(Folder)
			If Folder(I)<>"" And  Folder(I)<>".." Then
				Dir=Dir&Folder(I)&"\"
				If CheckFolder(Dir) Then
					CreateFolder=False
				Else
					Fso.CreateFolder(GetPath(Dir))
					CreateFolder=True
				End If
			End If
		Next
	Else
		If CheckFolder(FolderStr) Then
			CreateFolder=False
		Else
			Fso.CreateFolder(GetPath(FolderStr))
			CreateFolder=True
		End If
	End If
End Function

Function MoveFolder(Byval FolderDir,Byval NewFolderDir)
	If CheckFolder(FolderDir) And CheckFolder(NewFolderDir)=False Then
		Fso.MoveFolder GetPath(FolderDir),GetPath(NewFolderDir)
		MoveFolder=True	
	Else
		MoveFolder=False
	End If
End Function

Function CopyFolder(Byval FolderDir,Byval NewFolderDir)
	If CheckFolder(FolderDir) Then
		Fso.CopyFolder GetPath(FolderDir),GetPath(NewFolderDir)
		CopyFolder=True
	Else
		CopyFolder=False
	End If
End Function

Function DelFolder(Byval FolderDir)
	If CheckFolder(FolderDir) Then
		Fso.DeleteFolder(GetPath(FolderDir))
		DelFolder=True
	Else
		DelFolder=False
	End If
End Function

Function GetFolderList(Byval FolderDir)
	If CheckFolder(FolderDir)=False Then
		GetFolderList=False
		Exit Function
	Else
		Dim FolderObj,FolderList,F
		Set FolderObj=Fso.GetFolder(GetPath(FolderDir))
		Set FolderList=FolderObj.SubFolders
		GetFolderList=FolderObj.SubFolders.Count
		For Each F In FolderList
			GetFolderList=GetFolderList&"@"&F.Name
		Next
		Set FolderList=Nothing
		Set FolderObj=Nothing
	End If
End Function

Function GetFileList(Byval FolderDir)
	If CheckFolder(FolderDir)=False Then
		GetFileList=False
		Exit Function
	Else
		Dim FileObj,FileList,F
		Set FileObj=Fso.GetFolder(GetPath(FolderDir))
		Set FileList=FileObj.Files
		GetFileList=FileObj.Files.Count
		For Each F In FileList
			GetFileList=GetFileList&"@"&F.Name
		Next
		Set FileList=Nothing
		Set FileObj=Nothing
	End If
End Function

Function FormatSize(Byval SizeNum)
	FormatSize=SizeNum&"&nbsp;Byte"
	If SizeNum>1024 Then
		SizeNum=(SizeNum/1024)
		FormatSize=Formatnumber(SizeNum,2)&"&nbsp;KB"
	End If
	If SizeNum>1024 Then
		SizeNum=(SizeNum/1024)
		FormatSize=Formatnumber(SizeNum,2)&"&nbsp;MB"
	End If
	If SizeNum>1024 Then
		SizeNum=(SizeNum/1024)
		FormatSize=Formatnumber(SizeNum,2)&"&nbsp;GB"
	End If
End Function

End Class
%>