What are the commonly used file operation functions of FileSystem objects?
1. root
Function format root()
Function description returns a path string variable
Application code 'sample string = c:/intels/jingcaichunfeng/'
Public Function root()
root = Request.ServerVariables(Appl_Physical_Path)
End Function
2. URL
Function format url()
Function description returns a URL string variable
Application code 'sample string = http://www.intels.net/filesys.asp'
Public Function url()
url =http://&Request.ServerVariables(Server_Name)
&Request.ServerVariables(Script_Name)
End Function
3. mkdir
Function format mkdir(DIrName)
Function Description Create a directory and return information
Application codePublic Function mkdir(xVar)
Set Sys = Server.CreateObject(Scripting.FileSystemObject)
If Sys.FolderExists( xVar ) Then
msg =Sorry, the directory already exists!
Else
Sys.CreateFolder(xVar)
msg =Congratulations, the directory was created successfully!
End If
Set Sys=Nothing
mkdir = msg
End Function
4.rmdir
Function format rmdir(DirName)
Function DescriptionDelete a directory and return information
Application codePublic Function rmdir(xVar)
Set Sys = Server.CreateObject(Scripting.FileSystemObject)
If Sys.FolderExists( xVar ) Then
Sys.DeleteFolder(xVar)
msg =Congratulations, the directory has been deleted successfully!
Else
msg =Sorry, the directory has not been created yet!
End If
Set Sys=Nothing
rmdir = msg
End Function
5. isdir
Function format isdir(DirName)
Function description Checks whether a directory exists and returns information
Application codePublic Function isdir(xVar)
Set Sys = Server.CreateObject(Scripting.FileSystemObject)
If Sys.FolderExists( xVar ) Then
msg = True
Else
msg = False
End If
Set Sys=Nothing
isdir = msg
End Function
6.cpdir
Function format cpdir(DirName, Destination, OverWrite)
Function description: Copy folders and return information
Application codePublic Function cpdir(xVar, yVar, zVar)
Set Sys = Server.CreateObject(Scripting.FileSystemObject)
If Sys.FolderExists( xVar ) Then
Sys.CopyFolder xVar, root&yVar, zVar
msg =Congratulations, the directory copy was successful!
Else
msg =Sorry, the directory you were looking for was not found!
End If
Set Sys=Nothing
cpdir=msg
End Function
7. mvdir
Function format mvdir(DirName, Destination)
Function Description Move a folder and return information
Application codePublic Function mvdir(xVar, yVar)
Set Sys = Server.CreateObject(Scripting.FileSystemObject)
If Sys.FolderExists( xVar ) Then
Sys.MoveFolder xVar, root&yVar
msg =Congratulations, the directory has been moved!
Else
msg =Sorry, the directory you were looking for was not found!
End If
Set Sys=Nothing
mvdir = msg
End Function
8.isfile
Function format isfile(FileName)
Function description: Check whether the file exists and return information
Application codePublic Function isfile(xVar)
Set Sys = Server.CreateObject(Scripting.FileSystemObject)
If Sys.FileExists( xVar ) Then
msg = True
Else
msg = False
End If
Set Sys=Nothing
isfile = msg
End Function
9. wfile
Function format wfile(FileName, OverWrite, String)
Function description writes a string to a file and returns information
Application codePublic Function wfile(xVar, yVar, zVar)
Set Sys = Server.CreateObject(Scripting.FileSystemObject)
If yVar Then
Set Txt = Sys.OpenTextFile(xVar, 2)
Txt.Write(zVar)
Txt.Close
msg =Congratulations, the file was successfully created and saved!
Else
If Sys.FileExists( xVar ) Then
msg =Sorry, the file already exists!
End If
Set Sys=Nothing
wfile=msg
End Function
10. rfile
Function format rfile(FileName)
Function description reads a file and returns information
Application codePublic Function rfile(xVar)
Set Sys = Server.CreateObject(Scripting.FileSystemObject)
If Sys.FileExists( xVar ) Then
Set Txt = Sys.OpenTextFile(xVar, 1)
msg = Txt.ReadAll
Txt.Close
Else
msg =Sorry, the file does not exist!
End If
Set Sys=Nothing
rfile=msg
End Function
11. afile
Function format afile(FileName, String)
Function Description Adds a string to a file and returns the information
Application codePublic Function afile(xVar, zVar)
Set Sys = Server.CreateObject(Scripting.FileSystemObject)
If Sys.FileExists( xVar ) Then
Set Txt = Sys.OpenTextFile(xVar, 8)
Txt.Write(zVar)
Txt.Close
msg =Congratulations, the file was added successfully and saved!
Else
msg =Sorry, the file does not exist!
End If
Set Sys = Nothing
afile = msg
End Function
12.cpfile
Function format cpfile(FileName, Destination, OverWrite)
Function description: Copy a file and return information
Application codePublic Function cpfile(xVar, yVar, zVar)
Set Sys = Server.CreateObject(Scripting.FileSystemObject)
If Sys.FileExists( xVar ) Then
Sys.CopyFile xVar, root&yVar, zVar
msg =Congratulations, the file was copied successfully!
Else
msg =Sorry, file copy failed!
End If
Set Sys=Nothing
cpfile = msg
End Function
13. mvfile
Function format mvfile(FileName, Destination)
Function Description Move a file and return information
Application codePublic Function mvfile(xVar, yVar)
Set Sys = Server.CreateObject(Scripting.FileSystemObject)
If Sys.FileExists( xVar ) Then
Sys.MoveFile xVar, root&yVar
msg =Congratulations, the file was moved successfully!
Else
msg =Sorry, file move failed!
End If
Set Sys=Nothing
mvfile = msg
End Function
14.rmfile
Function format rmfile(FileName)
Function DescriptionDelete a file and return information
Application codePublic Function rmfile(xVar)
Set Sys = Server.CreateObject(Scripting.FileSystemObject)
If Sys.FileExists( xVar ) Then
Sys.DeleteFile(xVar)
msg =Congratulations, the file was deleted successfully!
Else
msg =Sorry, file deletion failed!
End If
Set Sys=Nothing
rmfile = msg
End Function