As mentioned earlier, this also just presses some functions together. Actually, it's better to use some of the function set methods to put the program.
Main function:
1, create Delete folder
2, get the name and number of folders in a folder
3, get the name and number of files in a folder
4, check if a folder exists
5, check if a file exists
6, delete the file
7, read the contents of a file
7, create a file, and write the contents into this file
In general, the function is divided into two, one is file operation, the other is folder operation. I am just based on my "online job management system" needs to write, not for everyone ...
<%
'***************************
' Name: FSO Operation class
' Author: West Building Cold Month
' Date: 2006-3-1
' URL: www.xilou.net/| www.chinaCMS.org
' Description: FSO Operation class
'***************************
Class Fsocls
Private Fso '//Object
Public fsoobj '//Common interface object
'//initialization, constructor
Private Sub Class_Initialize
Set fso=createobject ("Scripting.FileSystemObject")
Set Fsoobj=fso
End Sub
'//end, Release function
Private Sub Class_Terminate
Set fso=nothing
Set fsoobj=nothing
End Sub
' ==================== file operation started =========================
Function isfileexists (ByVal filedir)
' To determine if a file exists, to return true if it exists, or to return false
' Parameter filedir to the absolute path of the file
If fso.fileexists (Filedir) Then
Isfileexists=true
Else
Isfileexists=false
End If
End Function
Function Getfiletext (ByVal filedir)
' Read the contents of the file, if it exists, return the contents of the file, or false
' Parameter filedir to the absolute path of the file
If isfileexists (Filedir) Then
Dim F
Set F=fso.opentextfile (Filedir)
Getfiletext=f.readall
Set f=nothing
Else
Getfiletext=false
End If
End Function
Function CreateFile (ByVal filedir,byval filecontent)
' Create a file and write to the content
' Operation successfully returns TRUE, otherwise return false
If isfileexists (Filedir) Then
Createfile=false
Exit Function
Else
Dim F
Set F=fso.createtextfile (Filedir)
F.write filecontent
Createfile=true
F.close
End If
End Function
Function delfile (ByVal filedir)
' Deletes a file, returns true successfully, otherwise returns false
' Parameter filedir to the absolute path of the file
If isfileexists (Filedir) Then
Fso.deletefile (Filedir)
Delfile=true
Else
Delfile=false
End If
End Function
' ==================== file operation ended =========================
' ==================== folder operation started ========================
Function isfolderexists (ByVal folderdir)
' To determine if a folder exists, to return true if it exists, or to return false
' Parameter folderdir to the absolute path of the file
If fso.folderexists (Folderdir) Then
Isfolderexists=true
Else
Isfolderexists=false
End If
End Function
Sub Createfoldera (ByVal parentfolderdir,byval newfoldename)
'//Create a folder in a particular folder
'//parentfolderdir is the absolute path to the parent folder, NewFolderName is the name of the folder to be created
If isfolderexists (parentfolderdir& "\" &newfoldename) Then Exit Sub
Dim F,F1
Set F=fso.getfolder (Parentfolderdir)
Set f1=f.subfolders
F1. ADD (Newfoldename)
Set f=nothing
Set f1=nothing
End Sub
Sub Createfolderb (ByVal newfolderdir)
'//Create a new folder
'//Parameter newfolderdir is the absolute path of the folder to be created
If isfolderexists (newfolderdir) Then Exit Sub
Fso.createfolder (Newfolderdir)
End Sub
Sub Deleteafolder (ByVal newfolderdir)
'//delete a new folder
'//Parameter newfolderdir is the absolute path of the folder to be created
If isfolderexists (newfolderdir) =false Then
Exit Sub
Else
Fso.deletefolder (Newfolderdir)
End If
End Sub
Function FolderItem (ByVal folderdir)
'//Folder collection in folder
'//folderdir for folder absolute path
If isfolderexists (folderdir) =false Then
Folderitem=false
Exit Function
End If
Dim folderobj,folderlist,f
Set Folderobj=fso.getfolder (Folderdir)
Set folderlist=folderobj.subfolders
Folderitem=folderobj.subfolders.count '//Total folders
For each F in Folderlist
folderitem=folderitem& "|" &f.name
Next
Set folderlist=nothing
Set folderobj=nothing
End Function
Function Fileitem (ByVal folderdir)
'//File collection in folder
'//folderdir for folder absolute path
If isfolderexists (folderdir) =false Then
Fileitem=false
Exit Function
End If
Dim fileobj,fileerlist,f
Set Fileobj=fso.getfolder (Folderdir)
Set Filelist=fileobj.files
Fileitem=fileobj.files.count '//Total Files
For each F in FileList
fileitem=fileitem& "|" &f.name
Next
Set filelist=nothing
Set fileobj=nothing
End Function
' ==================== folder operation ended ========================
End Class
%>